Python Tuples can be thought of as Read-Only Lists. Tuple can store different datatype elements. A Tuple contains items separated by commas and enclosed within square parentheses ( ( ) ). Tuple is a collection which is ordered and unchangeable. Allows duplicate members.
Features of Python Tuples
- Ordered Lists
- Cannot change values after declaring elements
- Allow duplicate members
- Uses Parentheses ( )
- Can store different datatypes
Declaring Tuple in Python
tuple1 = ("Study", 123, 1.25, "Gyaan", 456)
tuple2 = ('Huzaif', 789)
Note – The plus (+) sign is the concatenation operator and the asterisk (*) is the repetition operator. For example −
tuple1 = ("Study", 123, 1.25, "Gyaan", 456)
tuple2 = ('Huzaif', 789)
print(tuple1)
print(tuple1[1])
print(tuple1[0:3])
print(tuple1[2:])
print(tuple2*2)
print(tuple1+tuple2)
- Posted on
- By huzaif
- Leave a comment
No comment yet, add your voice below!