Learn Python Easy Way - Tuples

Let us understand Tuples in Python. We had learnt Lists in Python in the previous article. Tuples can be understood in comparison to the Lists.

We created Lists. Lists were a set of objects enclosed in [ ] square braces. Tuples are also a set of objects but they are enclosed in ( ) brackets.

Both the data types are indexed. The elements can be accessed by their index numbers.

A Tuple can be understood as a finalized list. When we create a list, it can be appended, sorted, it's elements can be deleted, and new one's inserted etc. You can easily find out the number of operations that can be done on a list in your Python Shell

Whereas in a Tuple with similar elements, you can not insert, append or delete elements in a Tuple. Therefore I will term a Tuple as a finalized list that does not need to be altered. You can find out the operations that can be done on a Tuple in your Python Shell

You can display the elements of a List and a Tuple in the same way. You can view them full or slice them. You can even add two tuples using + operator. 

Therefore Tuples are lists that are enclosed in ( ) brackets. 

We can use both, Lists and Tuples in a dictionary. Incidentally Lists, Tuples and Dictionaries all three are termed as data types in Python. 

Featured Post

Creating Games in Scratch for ICSE Class 6

An Introduction to Creating Games in Scratch  for ICSE Class 6 Hello friends, I hope you have already read the previous post on An Int...