Tuples


clear()

The clear() method removes all elements from the set.

The syntax of clear() method is:
set.clear()

Example:-
vowels = {'a', 'e', 'i', 'o', 'u'}
print('Vowels (before clear):', vowels)
vowels.clear()
print('Vowels (after clear):', vowels)

Output:-
Vowels (before clear): {'e', 'a', 'o', 'u', 'i'}
Vowels (after clear): set()

count()

The count() method returns the number of occurrences of an element in a tuple.
The syntax of count() method is:
tuple.count(element)

Exmaple:-
vowels = ('a', 'e', 'i', 'o', 'i', 'o', 'e', 'i', 'u')
count = vowels.count('i')
print('The count of i is:', count)
count = vowels.count('p')
print('The count of p is:', count)

Output:-
The count of i is: 3
The count of p is: 0

index()

The index() method searches an element in a tuple and returns its index.

The syntax of index() method for Tuple is:
tuple.index(element)

Example:-

vowels = ('a', 'e', 'i', 'o', 'i', 'u')
index = vowels.index('e')
print('The index of e:', index)
index = vowels.index('x')

Output:- 
The index of e: 1
ValueError: tuple.index(x): x not in tuple

index()

The index() method searches an element in a tuple and returns its index.

The syntax of index() method for Tuple is:
tuple.index(element)

Example:-
vowels = ('a', 'e', 'i', 'o', 'i', 'u')
index = vowels.index('e')print('The index of e:', index)
index = vowels.index('i')
index = vowels.index('p')
 
Output:-
The index of e: 1
ValueError: tuple.index(x): x not in tuple