Welcome to the lesson on Python tuples
Tuples
Tuples is a fixed collection of data. It both lacks and adds on to the features a list can provide.
These are some of the main differences and similarities between lists and tuples.
Lists | Tuples |
---|---|
has a flexible number elements it can store | has a fixed number of elements it can store |
can store multiple values and elements | can store multiple values and elements |
created with square brackets [] | created with rounded brackets () |
consumes more memory | consumes lesser memory |
more built in functions | less built in functions |
Now that we have settled the differences and similarities, when should tuples be used?
Tuples should be used in situations where the group of data is only needed to be read. If you want to make changes to the data within the collection, use lists instead.
creation of tuples
As previously mentioned, tuples are created with a rounded bracket in place of a square bracket.
Example:

changing a tuple
Tuples are fixed collection of data, but there is a way to get around this tight rule.
by converting the tuple into a list , data can be editted and changed.
Example:

With conversion, it opens up all the list methods to tuples for easy use.
Unpacking
Tuples can be unpacked into individual variables too.
Example:

By calling variables inside rounded brackets, elements and values can be unpacked , and used individually.
Tuples methods
in comparison with the methods lists can use, tuples can only use the index() and count() functions.
End of Python Tuples
You have learned Tuples in simple terms. Let's proceed on to Quiz.