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
En esta página del sitio puede ver el video en línea PYTHON PROGRAMMING LAB Exp 6 de Duración hora minuto segunda en buena calidad , que subió el usuario DIWAKAR TIWARY 12 enero 2024, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto 49 veces y le gustó 1 a los espectadores. Disfruta viendo!