PYTHON PROGRAMMING LAB Exp 6

Опубликовано: 12 Январь 2024
на канале: DIWAKAR TIWARY
49
1

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


На этой странице сайта вы можете посмотреть видео онлайн PYTHON PROGRAMMING LAB Exp 6 длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь DIWAKAR TIWARY 12 Январь 2024, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 49 раз и оно понравилось 1 зрителям. Приятного просмотра!