Register Now


Lost Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.


Register Now

It will take less than 1 minute to register for lifetime. Bonus Tip - We don't send OTP to your email id Make Sure to use your own email id for free books and giveaways

Tuple in Python | Python for Data Science | Day 3

Hello, Python fam!
Let’s get started with an essential concept in Python i.e. Tuples. Like all programming languages, Python uses buckets i.e. data structures to hold data for further computation. Tuple is Python’s exclusive data structure that is immutable and supportive of comma-separated heterogeneous data.

Tuple in Python

Don’t get dazed by the image above. Tuples are pretty easy to comprehend. Stay with us for the rest of the article and you will find out. Firstly, the basic syntax of tuple is:

name_of_the_tuple= ( val1, val2, val3, ………)

The clouds of doubt fall with code. So, without further ado, let’s head straight to see some instances of tuple.

A tuple can consist of 

  • Integers:
  • Strings:
  • Heterogeneous data:

( consisting of strings, integers, and floats)

  • Boolean:

Can we store a single object in a tuple?

The answer is yes. But there’s a little trick here.

The type function is used to find the type of a variable. So, when we declare a tuple with only one element, why is the type displayed as string and not a tuple?

Type in the line of code below and you will get to know.

Here the type is tuple because of the comma that follows the first element. With this example, you now know that whenever you need to declare a tuple with a single element, the element should be followed by a comma.

Let’s try another line of code. 

We can access elements of a tuple by referring them through index numbers, starting from 0.

But can we alter the tuple elements by using their index numbers? Let’s find out.

As you must have observed above, tuple objects do not support item assignment.

Now, let’s try adding two tuples together. Try this-

You can also visit for some more examples.

Now, that we have learned a few things about tuples, it’s time to end this tutorial. But before that, let’s delete the tuple.

The error suggests that the tuple is deleted successfully.

If you tried the above examples of tuples, bravo! You must have got a good taste of our very first data structure in this series. If you haven’t yet, open your favorite IDE, and try them now!

When you are done, try these questions to test your knowledge. 

We have also answered the questions for your convenience. If you are stuck do not refrain from checking out the solutions. Happy learning 🙂 

We have covered 40+ complete Data Science company interviews from the candidates who cracked these interviews.
Data Science Companies interview questions
We also have 30+ e-books on Amazon, Insta Mojo and books which can be delivered directly on your email address
Complete Set of e-books from The Data Monk
Understand some of the very complex topics in Analytics which are asked in most of the interviews
The Data Monk Top Articles
How to become a Data Scientist? Complete study material, free resources and websites to practice
Become a Data Scientist 
Make your profile on our website and practice at least 5-7 questions per day. Be a part of ~2000 Analytics expert

Article By,
Yashika Khurana
Intern | The Data Monk

About TheDataMonkGrand Master

I am the Co-Founder of The Data Monk. I have a total of 6+ years of analytics experience 3+ years at Mu Sigma 2 years at OYO 1 year and counting at The Data Monk I am an active trader and a logically sarcastic idiot :)

Follow Me

Leave a reply