Use of Tuples in Python

Use of Tuples in Python

Instructor-svg Al-Mamun Sarkar
Apr 11 , 2021

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
  • Share On:
  • fb
  • twitter
  • pinterest
  • instagram