Exp No 6 Write a program to demonstrate working with tuples in python.
empty tuple
my_tuple = ()
print(my_tuple)
Output: ()
tuple having integers
my_tuple = (1, 2, 3)
print(my_tuple)
Output: (1, 2, 3)
tuple with mixed datatypes
my_tuple = (1, "Hello", 3.4)
print(my_tuple)
Output: (1, "Hello", 3.4)
nested tuple
my_tuple = ("mouse", [8, 4, 6], (1, 2, 3))
print(my_tuple)
Output: ("mouse", [8, 4, 6], (1, 2, 3))
tuple can be created without parentheses
also called tuple packing
my_tuple = 3, 4.6, 'dog'
print(my_tuple)
Output: 3, 4.6, 'dog'
tuple unpacking is also possible
a, b, c = my_tuple
print(a)
print(b)
print(c)
Output:
3
4.6
dog
INPUT AND OUTPUT:
()
(1, 2, 3)
(1, 'Hello', 3.4)
('mouse', [8, 4, 6], (1, 2, 3))
(3, 4.6, 'dog')
3
4.6
dog
Auf dieser Seite können Sie das Online-Video PYTHON PROGRAMMING LAB Exp 6 mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer DIWAKAR TIWARY 12 Januar 2024 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 49 Mal angesehen und es wurde von 1 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!