Tuple: Difference between revisions

From Computer Science Wiki
(Created page with "right|frame|Programming basics<ref>http://www.flaticon.com/</ref> A tuple is a data structure that is an immutable, or unchangeable, ordered sequence of e...")
 
No edit summary
 
(3 intermediate revisions by the same user not shown)
Line 5: Line 5:
As a general rule, tuples use less memory than a list or array.
As a general rule, tuples use less memory than a list or array.


Tuples allows for slicing and indexing like lists, but do not have access for deleting or changing any elements.  
Tuples allows for slicing and indexing like lists, but do not have methods for deleting or changing any elements.  


== Example ==  
== Example ==  
Line 14: Line 14:
mySiblings = ('Susan', 'James', 'Bryan')
mySiblings = ('Susan', 'James', 'Bryan')


# accessing an element within a tuple:


</syntaxhighlight>
mySiblings[2]




== Do you understand this?==
</syntaxhighlight>
 
== Standards ==


== External links ==
== External links ==

Latest revision as of 11:06, 20 June 2019

Programming basics[1]

A tuple is a data structure that is an immutable, or unchangeable, ordered sequence of elements. Because tuples are immutable, their values cannot be modified.[2]

As a general rule, tuples use less memory than a list or array.

Tuples allows for slicing and indexing like lists, but do not have methods for deleting or changing any elements.

Example[edit]

# creating a tuple 
mySiblings = ('Susan', 'James', 'Bryan')

# accessing an element within a tuple:

mySiblings[2]

External links[edit]

The discussion, examples, and formatting of this digital ocean article may be helpful for you to understand tuples

References[edit]