0% found this document useful (0 votes)
33 views14 pages

List, Tuple, Set, Dictionary Methods

Uploaded by

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

List, Tuple, Set, Dictionary Methods

Uploaded by

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

Lists, Tuple, Set,

Dictionary
methods
Lists
Python list is an ordered sequence of items.

ordered The items in the list are ordered.

changeable The items of the list can be modified.

heterogenous The items of the list can be of different data type.

duplicates The list can contain duplicates.


It is a collection of items which is ordered and
Unchangeable and allow duplicate values.
Tuple
Tuples are written with round brackets and can also
be created without parentheses.

The items in the tuple are ordered and that order willn’t
ordered change.
we cannot change, add or remove items after the tuple has
Unchangeable been created.
heterogenous The items of the tuple can be of different data type.

duplicates The tuple can contain duplicates.


Check if item exists Using in keyword
in tuple

Finding an item Using index() method.


in tuple It’ll return the index(position) of that item
If you try to modify the value you will get an error.
Change Tuple
Values As a workaround solution, we can convert the tuple to a
list, add items, and then convert it back to a tuple.
Add Tuple to a If you want to add one item to a tuple, create a new
Tuple with an item and add it to the existing tuple.
Tuple

Convert tuple into list. Remove item from the list and then
Remove items from convert list back into Tuple. Or use del() method
Tuple to remove tuple.
When we create a tuple, we normally assign values to it. This is
Unpack Tuple called "packing" a tuple.

But, in Python, we are also allowed to extract the values back into
variables. This is called "unpacking"

If the number of variables is less than the number of values, you


Using Asterisk * can add an * to the variable name and the values will be assigned
to the variable as a list
Sets
Python Set is an unordered collection of items that are unique.
Sets are written with curly brackets { }.

The items in the set will be in different order each time you
unordered access the set.
unchangeable We can’t change the set items.

unique Each item in the set will be unique.


Dictionary

unordered The order of the objects is unimportant.

Changeable The data can be changed.

Key-value pair Key is the index which helps to access value from it.
unique It stores unique values.

Mutable Key-values can be changed after creation.

You might also like