Tuple Data Type
suggest changeLists are enclosed in square brackets and their elements and size can be changed, while tuples are enclosed in parentheses ( ) and cannot be updated. Tuples are immutable.
tuple = (123,'hello')
tuple1 = ('world')
print(tuple) #will output the whole tuple. (123, 'hello')
print(tuple[0]) #will output the first value, 123, not (123)
print(tuple + tuple1) #TypeError: can only concatenate tuple (not "str") to tuple
tuple[1]='update' #TypeError: 'tuple' object does not support item assignment
('world') is a string. A one-element tuple needs a trailing comma, ('world',). The name tuple also shadows the built-in.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents