Programming with Python

  1. Home
  2. Docs
  3. Programming with Python
  4. Tuples in python
  5. Working with Tuples in python

Working with Tuples in python

As we know that tuples are immutable, so we cannot add, insert or delete an element from a tuple. We cannot modify tuples.

Working with tuples means two basic operations on a tuple i.e., comparing two tuples and Deleting a tuple.

Comparing two tuples:-

We can compare two tuples without having to write with loops for it. We can use comparison operators for this.

e.g.,

a=(1, 2, 3)
b=(5, 6, 7)
a==b
c=(1,2,3)
a==c
Output- False
        True

Deleting tuple:-

As we know tuples are immutable i.e., it cannot be modified, so we cannot delete any item from it. We will delete the whole tuple.

e.g.,

a=(1,2,3,4,5)
print(a)
del a
print(a)
Output- 
(1,2,3,4,5)
NameError: name 'a' is not defined.
Was this article helpful to you? Yes No

How can we help?