Tuples are very similar to lists, except that they are immutable (they cannot be changed).
Also, they are created using parentheses, rather than square brackets.
words = (“spam”, “eggs”, “sausages”,)
You can access the values in the tuple with their index, just as you did with lists:
Trying to reassign a value in a tuple causes a TypeError.
words = “cheese”
TypeError: ‘tuple’ object does not support item assignment
Tuples can be created without the parentheses, by just separating the values with commas.
my_tuple = “one”, “two”, “three”
An empty tuple is created using an empty parenthesis pair.
tpl = ()
CLICK ON THE BUTTON BELOW TO GO TO THE PYTHON MAIN COURSE PAGE.
©️ License: All Rights Reserved
CONTACT HOLLA TECH – LEARN SUPPORT