Python Tutorial
About Lesson

In this Python Tuple lesson we want to learn about Creating Tuples in Python, so first of all what are tuples ? tuples are a collection of data value which is immutable,  it means that we can not change a tuple and it is unchangeable. you can use parenthesis for creating tuples in python.

 

 

OK now let’s create our first Tuple in Python.

In the above code we have created a simple tuple of programming language, also we have printed the type, you can see that we are receiving a tuple class for the type.

 

 

Run the code and this is the result.

Python Tuple - Creating Tuples in Python
Python Tuple – Creating Tuples in Python

 

 

 

Accessing a Tuple Item

You can access a tuple item by using the index of that item, and indexing starts from 0, for example in here i want to access item 0 and 2 from the tuple.

 

 

 

This is the result.

Python Tuple
Python Tuple

 

 

 

If you want to access the last item you can use negative indexing.

 

 

 

Also you can do ranging index.

Now this will start from index 1 and end at index 4 but it will not include index 4 item.

 

 

 

This is the result.

Tuples in Python
Tuples in Python

 

 

 

Converting Python Tuple to Python List

As i have already said that you can not change tuples, for example if you want to add a new item in python tuples, you can not do that, because tuples are immutable, but there is a ways that you do this. you can convert your tuples to Python List, as you know you can change a list in python, after that add your item and than you can convert list to tuple.

 

 

 

This is the result.

Convert Tuple to List
Convert Tuple to List

 

 

 

Joining Python Tuples

You can join two tuples in Python.

 

Thank you for visiting my website! If you enjoyed the free courses, please consider supporting my works on Patreon.
Exercise Files
No Attachment Found
No Attachment Found