OR Is tuple mutable ? Demonstrate any two method of tuple
No tuple is not mutable(changeble)
A tuple in Python is similar to a list.
we cannot change the elements of a tuple once it is assigned
A Tuple is a collection of Python objects separated by commas.
Creating Tuples Program:
tup = ‘python’, ‘geeks’ print(tup)
Output: (‘python’, ‘geeks’)
Tuple Method: count():
returns occurrences of element in a tuple
count() method searches the given element in a tuple and returns how many times the element has occurred in it.
Program: vowels = ('a', 'e', 'i', 'o', 'i', 'o', 'e', 'i', 'u') x = vowels.count('i') print('The count of i is:', x) Output: The count of i is: 3
Tuple Method: Len():
The len() function returns the number of items (length) in an object.
Program: est = [1, 2, 3] print(‘Length of test is: ’) print(len(testList)) Output: Length of test is: 3