List
Last updated
Last updated
Method name
Description
x in s
True
if element x is in sequence s, False
otherwise
x not in s
True
if element x is not in sequence s, False
otherwise
s1 + s2
Concatenates two sequences s1 and s2
s * n
, n * s
n
copies of sequence s
concatenated
s[i]
ith element in sequence s
.
len(s)
Length of sequence
s, i.e. the number of elements in
s`.
min(s)
Smallest element in sequence s
.
max(s)
Largest element in sequence s
.
sum(s)
Sum of all numbers in sequence s
.
for loop
Traverses elements from left to right in a for loop.
Method name
Description
append(x:object):None
Adds an element x
to the end of the list and returns None
.
count(x:object):int
Returns the number of times element x appears in the list.
extend(l:list):None
Appends all the elements in l
to the list and returns None
.
index(x: object):int
Returns the index of the first occurrence of element x
in the list
insert(index: int, x: object):None
Inserts an element x
at a given index. Note that the first element in the list has index 0
and returns None
.
remove(x:object):None
Removes the first occurrence of element x
from the list and returns None
reverse():None
Reverse the list and returns None
sort(): None
Sorts the elements in the list in ascending order and returns None
.
pop(i): object
Removes the element at the given position and returns it. The parameter i
is optional. If it is not specified, pop()
removes and returns the last element in the list.