List values must be given within [] square braces.
List is mutable (modifiable)
- Tuple values must be given within () parenthesis.
- List values must be given within [] square braces.
- List is used to store group of values under same name.
- List allows duplicate values.
- List can store group of different type of values.
- List is indexed and ordered.
solution:
<class 'list'>
marks= [41, 86, 94, 74, 41, 58]
41
86
94
74
41
58
solution:
minimum= 41
maximum= 94
sum= 415
length= 6
sorted marks= [41, 58, 62, 74, 86, 94]
Traceback (most recent call last):
File "C:/Users/Darshan /Desktop/functions which works on tuple, list, set and dict..py", line 9, in <module>
print('marks=',marks)
NameError: name 'marks' is not defined. Did you mean: 'vars'?
solution:
d= [2, 4, 6, 1, 3, 9, 12, 4, 6, 8]
solution:
b= [2, 5, 9, 2, 5, 9, 2, 5, 9]
solution:
[6, 8, 10, 12, 14, 16]
[10, 12, 14, 16, 18, 20]
[2, 4, 6, 8, 10, 12]
[12, 14, 16, 18, 20, 22, 24, 26, 28, 30]
30
28
[6, 10, 14, 18, 22]
[2, 6, 10, 14, 18, 22, 26, 30]
[4, 8, 12, 16, 20, 24, 28]
[30, 28, 26, 24]
[30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2]
List is mutable(modifiable)
- Can insert single value using append function.
- It adds the given value at the end of list. can insert single value using append function.
solution:
[20, 80, 40, 20, 50, 80, 20, 15, 25, 35]
solution:
[80, 40, 20, 50, 80, 20]
solution:
[20, 80, 40, 60, 50]
solution:
a= [10, 20, 50, 60, 50, 20.3, '#', 'list']
a= []
Copy Function: This function used to copy entire list values to another list.
solution:
a= [20, 23.5, '#', 'Hello']
b= [20, 23.5, '#', 'Hello']
- Count Function: This function gives number of occurrences of gives element.
- Index Function: This function gives index of given values.
solution:
3
2
1
0
0
1
Extend Function: Extend used to add multiple elements at the end of the list.
solution:
e= [10, 20, 30, 40, 2, 4, 6, 8]
Insert Function: used to insert the element at given posotion.
solution:
a=[10,50,40,80,100,30]
pop function: pop used to remove last item in the list.
solution:
p=[10,20,40,60]
Remove function used to remove given element from the list.
solution:
p= [10, 20, 70, 30]
Sort Function: used to sort the elements in ascending order.
solution:
p= [10, 20, 30, 50, 60, 70, 80]
Reverse Function: used to reverse the elements in the list.
solution:
p= [30, 70, 50, 20, 60, 10, 80]