0% found this document useful (0 votes)
24 views3 pages

Lists Tuples Sets

Lists and tuples are both sequence data types that allow duplicate elements and can contain elements of different data types. The main differences are that lists are mutable and their size can change, while tuples are immutable and their size cannot change. Common built-in functions for lists and tuples include len() to get the length, max() and min() to find the maximum and minimum values, and list() to convert a tuple to a list.

Uploaded by

praneethgowda11
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views3 pages

Lists Tuples Sets

Lists and tuples are both sequence data types that allow duplicate elements and can contain elements of different data types. The main differences are that lists are mutable and their size can change, while tuples are immutable and their size cannot change. Common built-in functions for lists and tuples include len() to get the length, max() and min() to find the maximum and minimum values, and list() to convert a tuple to a list.

Uploaded by

praneethgowda11
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Lists

• List is a sequence datatype and it is a collection of


elements which is ordered and changeable. Allows
duplicate members also.
• A Python list contains items separated by commas and
enclosed within square brackets ([]).
• One difference between them is that all the items
belonging to a Python list can be of different data type
where as C array can store elements related to same
data type.
• The values stored in a Python list can be accessed using
with index starting at 0 from beginning of the list and
the values stored in a Python list can be accessed
using with index starting at -1 from ending of the
list.
• The values stored in a Python list can be accessed using
the slice operator ([:]).

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

2. len(list) - It Returns length of string or set

3. max(list) - It Returns item that has Maximum value in a


list

4. min(list) - It Returns item that has Minimum value in a


list

5. list(seq) - It converts a tuple/set into a list

6. list.append(item) - It adds the item to the end of the list

7. list.count(item) - It returns number of times the item


occurs in a list

8. list.index(item) - It returns the index number of the item.

9. list.insert(index,item) - It inserts the given item on the the


given index number in the list

10 list.reverse()- It reverse the position(index number) of the


items in the list
11. list.sort() - It sorts the elements inside the list

12. list.extend(seq) - It adds the elements of the sequence at


the end of the list

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.

You might also like