Python – Tuples

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

  1. Ordered Lists
  2. Cannot change values after declaring elements
  3. Allow duplicate members
  4. Uses Parentheses ( )
  5. 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)
Filed under: Python

No comment yet, add your voice below!


Leave a Reply