An Introduction to Tuples in Python for Beginners
Understanding Tuples with examples, operations with Tuples, zip, and Tuple function.

Hello, Python Enthusiasts!
In the last section of this Python Tutorial Series, We talked about Python Lists and understood them with some examples. In this article, we will go a step further. We are going to deal with Tuple in the Python programming language. It is an easy concept but very helpful for the everyday programmer who works on project-based. If you are an absolute beginner then it’s okay. We are going to understand Tuple from a very beginner level. If you are following this Python Tutorial Series then it will be easy for you to understand.
Attention all developers seeking to make social connections and establish themselves while earning passive income — look no further! I highly recommend ‘From Code to Connections’, a book that will guide you through the process. Don’t miss out, grab your copy now on Amazon worldwide or Amazon India! You can also go for Gumroad
Tuples
A tuple is a non-scalar type defined in Python. Tuples are immutable too, i.e. elements of a tuple cannot be overwritten. Just like a list, a tuple is an ordered sequence of objects. You can specify a tuple by enclosing the element inside parentheses. The element of the tuples can be heterogeneous types. For example:
>>> example = (2, 4, 6, 8, 'abcd', [10, 12], {3, 5})
>>> type(example)
<class 'tuple'>
A tuple having a single element is also known as a singleton tuple. For example:
>>> (7,)
7,
As we already know that tuples are immutable. If you try to modify the elements of the tuple then it will lead to you an error. For example:
>>> example1 = (1, 2, 3, 4, 5, 6, 7, 8)
>>> example1[2] = 9
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'tuple' object does not support item assignment
However, if the element of the tuple is a mutable object, then you can change its corresponding value. For example:
>>> example2 = (1, 2, 3, [4, 7], 5, 9)
>>> example2[3][1] = 99
>>> example2
(1, 2, 3, [4, 99], 5, 9)
Tuple Operations
- Multiplication
>>> example3 = (1, 2, 3, 'abc')
>>> example3*2
(1, 2, 3, 'abc', 1, 2, 3, 'abc')
- Concatenation Operation
>>> example4 = example3 + ('Apple',)
>>> example4
(1, 2, 3, 'abc', 'Apple')
- Length Operation
>>> len(example4)
5
- Indexing
>>> example4[-1]
'Apple'
- Slicing
>>> example4[1:3]
(2, 3)
- min Function
>>> example5 = (5, 6, 58, 684, 5, 4, 69)
>>> min(example5)
4
- max Function
>>> max(example5)
684
- sum Function
>>> sum(example5)
831
- Membership operator in
>>> 58 in example5
True
Functions zip and tuple
The function tuple can be used to convert a sequence to a tuple, for example:
>>> game = 'cricket'
>>> tuple(game)
('c', 'r', 'i', 'c', 'k', 'e', 't')>>> tuple(range(7))
(0, 1, 2, 3, 4, 5, 6)
The function zip is used to produce a zip object. It can be more clear with an example.
>>> sports = ('cricket', 'football', 'Basketball')
>>> player = ('Virat Kohli', 'Ronaldo', 'Kobe Bryant')
>>> jersy = (18, 7, 24)>>> sportsPlayer = list(zip(sports, player))
>>> sportsPlayer
[('cricket', 'Virat Kohli'), ('football', 'Ronaldo'), ('Basketball', 'Kobe Bryant')]>>> All = list(zip(sports, player, jersy))
>>> All
[('cricket', 'Virat Kohli', 18), ('football', 'Ronaldo', 7), ('Basketball', 'Kobe Bryant', 24)]
That’s it for this article. I hope I covered all the topics related to the Python Tuple. If I missed something then let me know in the comment section.
Well, that’s it for this article. In the next article, we will look after Python Dictionary
If this article sounds informative to you then make sure to follow and clap. Share it with your geek community.
Thanks for reading.
Hello, My Name is Rohit Kumar Thakur. I am open to freelancing. I build React Native projects and I am currently working on Python Django. Feel free to contact me at (freelance.rohit7@gmail.com).
More content at plainenglish.io. Sign up for our free weekly newsletter here.