Skip to content

Instantly share code, notes, and snippets.

@gideondsouza
Last active December 22, 2015 10:39
Show Gist options
  • Save gideondsouza/6460607 to your computer and use it in GitHub Desktop.
Save gideondsouza/6460607 to your computer and use it in GitHub Desktop.
Introducing a tuple
>>> #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