List
Common List Operations
Method name | Description |
|
|
|
|
| Concatenates two sequences s1 and s2 |
|
|
| |
|
|
| Smallest element in sequence |
| Largest element in sequence |
| Sum of all numbers in sequence |
for loop | Traverses elements from left to right in a for loop. |
List examples using functions
List slicing
+
and *
operators in list
+
and *
operators in listin
or not in
operator
in
or not in
operatorTraversing list using for loop
List Comprehension
Commonly used list methods with return type
Method name | Description |
append(x:object):None | Adds an element |
count(x:object):int | Returns the number of times element x appears in the list. |
extend(l:list):None | Appends all the elements in |
index(x: object):int | Returns the index of the first occurrence of element |
insert(index: int, x: object):None | Inserts an element |
remove(x:object):None | Removes the first occurrence of element |
reverse():None | Reverse the list and returns |
sort(): None | Sorts the elements in the list in ascending order and returns |
pop(i): object | Removes the element at the given position and returns it. The parameter |
Last updated