Lists Tuples Sets
Lists Tuples Sets
Tuples
• Python tuple is another sequence data type that is
similar to a list. Tuple is a collection of elements which
is ordered and unchangeable. Allows duplicate
members also.
• A Python tuple consists of a number of values separated
by commas. however, tuples are enclosed within
parentheses.
• The main differences between lists and tuples are: Lists
are enclosed in brackets ( [ ] ) and their elements and
size can be changed, while tuples are enclosed in
parentheses ( ( ) ) and cannot be updated.
• Tuples can be thought of as read-only lists.
Common Built-in Functions of Lists and Tuples in Python:
1. cmp(list1,list2) - It compares the elements of both lists,
list1 and list2
SETS
A set is a collection of elements which are unordered,
unchangeable, and unindexed.
Sets are written with curly brackets (Braces).
Note: Set items are unchangeable i.e the items cannot
be changed after creating the set.
You can remove items from the sets and add new items
into the sets.
Sets are Not Allowed Duplicates Elements. i.e. Sets
cannot have two items with the same value.