Last active
December 22, 2015 10:39
-
-
Save gideondsouza/6460607 to your computer and use it in GitHub Desktop.
Introducing a tuple
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> #The tuple is a common CS structure. | |
>>> T = (1,2,3) #think of it as a record | |
>>> type(T) | |
<class 'tuple'> | |
#you're not limited to numbers, you can store anything in a tuple, list, set etc. | |
>>> Friends = ("Bill", "Bob", "Will") | |
>>> Friends[0] #access it's first element. | |
'Bill' | |
>>> T[2] | |
3 | |
#tuples are immutable and don't support assignment. | |
>>> T[1] = 3 | |
Traceback (most recent call last): | |
File "<stdin>", line 1, in <module> | |
TypeError: 'tuple' object does not support item assignment | |
>>> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment