Tuples in Python

filler(58)
Published in
#python
Words
165
Reading
1 min
7y
Listen to this post
~1 min

The first thing that we learn about tuples is that they are immutable. It means it cannot be changed.

Tuples can be compared to lists but the values cannot be changed as we do in the case of lists.

Capture.JPG

The above screenshot shows coordinates being represented by a Tuple.
The values are indexed and so, the first index gives the result 5 because the number 5 is at the first position and 4 is at the zero position.

immutable.JPG

The screenshot shows the error message printed out by Python when we try to change the value. It is because tuples are immutable which means we cannot change the values.

Tuples can also be made without the parentheses.

apple.JPG

Remember that you will get error messages if you capitalize on the word p.

By practice, I wrote Print instead of print and got an error message.

So, there is nothing complex about it and with continuous practice, we will get it right.

Images are screenshots of Google colab.