Tuple are used to store multiple items in a single variable.To separate two items, you use a comma ( , ) . A tuple is like a list except that it uses parentheses ( ) . Once you define a tuple, you can access an individual element by its index. A tuple is a collection of objects which ordered and immutable, you cannot change its elements. Tuples are sequences, just like lists.
This program demonstrates the usage of tuples in Python. A tuple is a collection of ordered and immutable elements, that are enclosed within parentheses. The elements in a tuple can be of different data types.
# Tuple in Python # Immutable # Surrounded by Round Brackets (1,1,5) a = (1, 2.5, True, "Ram") print(a) print(type(a)) print(a[1]) print(a[-1]) print(a[0:2]) b = list(a) print(b) b.append("Raja") print(b) print(type(b)) a = tuple(b) print(a) print(type(a)) for i in a: print(i) if "Raj" in a: print("Raja is Found") else: print("Not Found") print(len(a)) a = (1,) print(type(a)) del a a = (1, 2, 7, 4) b = (5, 6, 7, 8) c = a + b print(c) print(c.count(7)) a = (1, 2, 7, 4) b = (5, 6, 7, 8) c = (a, b) print(c) print(c[0]) print(c[1]) print(c[0][1]) x = ('Joes',) * 10 print(x) a = (1, 2, 7, 4) b = (5, 6, 7, 8) print(min(a)) print(max(a))To download raw file Click Here
(1, 2.5, True, 'Ram')2.5 Ram (1, 2.5) [1, 2.5, True, 'Ram'] [1, 2.5, True, 'Ram', 'Raja'] (1, 2.5, True, 'Ram', 'Raja') 1 2.5 True Ram Raja Not Found 5 (1, 2, 7, 4, 5, 6, 7, 8) 2 ((1, 2, 7, 4), (5, 6, 7, 8)) (1, 2, 7, 4) (5, 6, 7, 8) 2 ('Joes', 'Joes', 'Joes', 'Joes', 'Joes', 'Joes', 'Joes', 'Joes', 'Joes', 'Joes') 1 7
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions