What is a Tuple in Python
A tuple is a collection of objects which ordered and immutable. Tuples are sequences, just like lists. The differences between tuples and lists are, the tuples cannot be changed unlike lists and tuples use parentheses, whereas lists use square brackets.
A tuple can be created by putting different comma-separated values. Optionally you can put these comma-separated values between parentheses also.
>>> t = 1, 2, 3, 4, 5 >>> type(t) <class 'tuple'> >>> tu = (1, 3, 5) >>> type(tu) <class 'tuple'>
The empty tuple is written as two parentheses containing nothing −
tup1 = ()
Like string indices, tuple indices start at 0, and they can be sliced, concatenated, and so on.
Please login to comment
View all comments