➜ In Python, A Tuple is an immutable data_type and it places an inside the round bracket, it is a collection of values that can be of different types.
➜ A tuple is the same as List the difference is List is mutable where the tuple is not.
➜ A tuple is a collection that is ordered and unchangeable. Allows duplicate members.
tup = (21, 36, 14, 25)
print(tup)
print(tup[1])
tup[1] = 33 # here we got an error because tuple is immutable
# Execution of tuple is faster than the execution of list, to enhance our program or to for more security we use a tuple
''' More about Tuples '''
# Element of Tuple can change if the element is Mutable like list or Dictionary:
tp = (12, 21, 'akash', 23, ['macskill', 15, 4])
tp[4][0] = 'kumar_singh' # This can be change as it is Mutable Datatype i.e. List
print(tp)
''' Unpacking Of Tuples '''
person1 = ("Akash", 15, '12th')
person2 = ("Pyush", 19, 'Collage')
(name, age, clas) = person1
print(name)
print("Age :", age, ", Class :", clas)
# OR
people = person1, person2
for name, age, clas in people:
print("Name ->", name)
print("Age ->", age)
print("Studying in ->", clas)
print()