Difference between Tuple and List
in Python at TCCI
• Tuple and List are used to store data in Python Language.
• Tuple: A tuple is a collection of values and it is declared using
parentheses. However, we can also use a tuple packing to do the
same, and unpacking to assign its values to a sequence.
• Lists: Unlike in C++, we don’t have arrays to work with in Python.
Here, we have a list instead.
– A List is Mutable
– B Tuple is Immutable
In built Methods:
– Following Methos can apply to List append(), insert(), remove(), pop(),
clear(), sort(), and reverse().
– But not applicable to Tuple.
– We can store tuples in a list when we want to. For example,
– [(1, ‘ABC’), (2, ‘DEF’), (3, ‘GHI’)]
– Lists in a Tuple
– Likewise, we can also use a tuple to store lists. Let’s see how.
– >>> mytuple=([1,2],[3,4],[5,6])
– Use a tuple when you know what information goes in the container
that it is. For example, when you want to store a person’s credentials
for your website.
– >>> person=('ABC','admin','12345') But when you want to store similar
elements, like in an array in C++, you should use a list.
– >>> groceries=['bread','butter','cheese']
• TCCI-Tririd Computer Coaching Institute is focused on providing
Quality education with practical sessions.
• We pride ourselves for providing proficient IT solutions.
• We have a highly qualificated and expereinced faculties, who
provide teaching for all computer subjects and All Engineering
Call us @ 98256 18292
Visit us @ http://tccicomputercoaching.com/
Thank you for watching