LIST
List is a data structure which can hold multiple values |
It can be defined using [] or list() `lst = [1,2,3,4] lst2 = list((1,2,3,4))' |
It can be a collection of different data types list1 = [1,"hi",2.5,False] |
It can be accessed by indexing and is ordered print(list1[2]) ---->2.5 |
We can modify the values of the list using indexing- mutable list1[3]="hello"------>[1,"hi",2.5,"Hello"] |
|
|
TUPLE
Tuple is a data structure which can hold multiple values |
It can be defined using () or list() `tup= [1,2,3,4] tup2= tuple((1,2,3,4))' |
It can be a collection of different data types tup2= (1,"hi",2.5,False) |
It can be accessed by indexing and is ordered print(tup2[2]) ---->2.5 |
We cannot modify the values of the tuple using indexing- immutable tup2[3]="hello"------>error |
|
|
SETS
Set is a data structure which can hold multiple values |
It can be defined using {} or set() `set1= {1,2,3,4} set2 = set((1,2,3,4))' |
It can be a collection of different data types set1= {1,"hi",2.5,False} |
Itcannot be accessed by indexing and is unordered print(set2[2]) ---->error |
We can modify the values of the list using iteration- mutable |
|
|
dictionary
Dictionary is a data structure which can hold multiple values |
The values are stored in a key value pair |
It can be defined using () or dict() `dict1= ("Name":"Tom","age":23) lst2 = list((1,2,3,4))' |
It can be a collection of different data types list1 = [1,"hi",2.5,False] |
It can be accessed by indexing and is in order print(list1[2]) ---->2.5 |
We can modify the values of the list using indexing- mutable list1[3]="hello"------>[1,"hi",2.5,"Hello"] |
|