Python Tuple

Filed Under: Python

Today we are going to learn about Python Tuple. This is very similar to Python List. If you don’t know about list you can find them here.

Python Tuple

Python tuple is a sequence of Python objects. They are lot like lists. But the differences between a tuple and a list is that tuples can not be changed like we can change an item of a list. Also tuples use parentheses while lists use square brackets.

Python Tuple is a sequence of comma-separated values between parentheses. For example;

#an empty tuple

#tuple of string

#tuple of integers

Accessing a Value in Python Tuple

Accessing a value in a python tuple is quite similar to the way to access an item in a list. Through index number we can access a value in a tuple. First element has index number zero, second has index number one, and so forth.

#tuple of string

#accessing first element

#accessing second element

#accessing fourth element

The output of the above code will be like below-

python tuple example, accessing a value in python tuple example

Tuple in python also support negative indexing like list. A negative index means index number from the right of that tuple.

#tuple of string

#accessing first element from the right

#accessing second element from the right

#accessing second element from the right

The output will be like below.

python tutorial, tuple accessing a value with negative index example output

Update and Delete in Python Tuple

As we have mentioned earlier tuples in python are not changeable. So you can not update a single tuple element. But we can take two tuple and concat them to create a new one.

Also removing an individual tuple element is not possible. Though we can remove an entire tuple using del statement.

#tuple 1

#tuple 2

#tuple 3


#to delete tuple 1
del tup1
#this will show a traceback as tup1 is deleted. So it is not defined now

The above code’s output will be like following picture.

python tuple tutorial, tuple update and delete example output

Some built-in Python Tuple Functions

There are some built-in functions available to manipulate tuple in python. Take a look at the following code for understanding.

#a string tuple


#len(tuple) gives total length of a tuple

#max(tuple) gives maximum element of a tuple

#min(tuple) gives minimum element of a tuple

#count(x) gives number of occurances of x in the tuple

#index(x) gives index of first occurances of x in the tuple

You should get the following output if you run the above code.

python tuple, some built-in tuple functions example

So that’s it for python tuple. Make sure to run every piece of code on you own. Feel free to leave a comment if you have any doubt.
#happy_coding 馃檪



  1. Jay says:

    Great and very clear explanations! Thank you!

Leave a Reply

Your email address will not be published. Required fields are marked *

Generic selectors
Exact matches only
Search in title
Search in content
Search in posts
Search in pages