Use of Tuples in Python

Author: Al-mamun Sarkar Date: 2021-04-11 02:50:42

The tuple is the same as a list but it's immutable. We can access a tuple like a list but can't update data, can't add data, and can't remove data.

 

Create Tuple:

names = ("Jone", "Doe", "Jems")
print(names)

Accessing items:

print(names[0])
print(names[1])

 

Getting the length of Tuple:

names = ("Jone", "Doe", "Jems")
print(len(names))

 

Check if an item present in the tuple:

print("Doe" in names)

Delete the tuple:

del names

 

Tuple Methods:

Method Description
count() Used to get the number of times a given value occurs in a tuple
index() Used to search the position of a specified value