List
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
Creation of a list :�
1 | 2 | 2 | 3 | 3 | 3 | 4 | 4 | 4 | 4 |
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
1 | 2 | s | hai | 1.23456 |
0 | 1 | 2 | 3 | 4 |
�
Accessing Elements of List:
5 | 10 | 15 | 20 |
0 | 1 | 2 | 3 |
|
“VVIT” | |
0 | 1 | 2 |
1 | 2 | 3 |
4 | 5 | 6 |
0 | 1 | 2 |
0 | 1 | 2 |
5 | 10 | 15 | 20 |
0 | 1 | 2 | 3 |
-4 | -3 | -2 | -1 |
Python List Methods |
append() - Add an element to the end of the list |
extend() - Add all elements of a list to the another list |
insert() - Insert an item at the defined index |
remove() - Removes an item from the list |
pop() - Removes and returns an element at the given index |
clear() - Removes all items from the list |
index() - Returns the index of the first matched item |
count() - Returns the count of number of items passed as an argument |
sort() - Sort items in a list in ascending order |
reverse() - Reverse the order of items in the list |
copy() - Returns a shallow copy of the list |
�Change or add elements to a list (because list is ‘mutable’):�
1.append()
2.insert()
3.extend()
List Operators :
1. Slicing Operator (:)
2. Concatenation (+)
3. repeat Operator (*) :