1list.append(x) # append x to end of list
2list.extend(iterable) # append all elements of iterable to list
3list.insert(i, x) # insert x at index i
4list.remove(x) # remove first occurance of x from list
5list.pop([i]) # pop element at index i (defaults to end of list)
6list.clear() # delete all elements from the list
7list.index(x[, start[, end]]) # return index of element x
8list.count(x) # return number of occurances of x in list
9list.reverse() # reverse elements of list in-place (no return)
10list.sort(key=None, reverse=False) # sort list in-place
11list.copy() # return a shallow copy of the list
1# list() converts other datatypes into lists
2
3# e.g.
4
5text = 'Python'
6
7# convert string to list
8text_list = list(text)
9print(text_list)
10
11# check type of text_list
12print(type(text_list))
13
14# Output: ['P', 'y', 't', 'h', 'o', 'n']
15# <class 'list'>
1# Create a list
2new_list = []
3
4# Add items to the list
5item1 = "string1"
6item2 = "string2"
7
8new_list.append(item1)
9new_list.append(item2)
10
11# Access list items
12print(new_list[0])
13print(new_list[1])
1#creating the list
2whatever_list = ["apple", "orange", "pear"]
3
4#adding things to lists:
5whatever_list.append("banana") #adds banana on to the list
6
7#printing something from the list.
8#remember, lists start from zero!
9print(whatever_list[0]) #This prints apple
10print(whatever_list[1]) #This prints orange and so on.
11
12#removing something from a list
13whatever_list.remove("orange")
14
15#these are the basic list functions.