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
1list.append()
2list.clear()
3list.copy()
4list.count()
5list.extend()
6list.index()
7list.insert()
8list.pop()
9list.remove()
10list.reverse()
11list.append()
12list.clear()
13list.copy()
14list.count()
15list.extend()
16list.index()
17list.insert()
18list.pop()
19list.remove()
20list.reverse()
21list.sort()
22sorted(list)
1my_list = ["banana", "cherry", "apple"]
2
3# len() : get the number of elements in a list
4print("Length:", len(my_list))
5
6# append() : adds an element to the end of the list
7my_list.append("orange")
8
9# insert() : adds an element at the specified position
10my_list.insert(1, "blueberry")
11print(my_list)
12
13# pop() : removes and returns the item at the given position, default is the last item
14item = my_list.pop()
15print("Popped item: ", item)
16
17# remove() : removes an item from the list
18my_list.remove("cherry") # Value error if not in the list
19print(my_list)
20
21# clear() : removes all items from the list
22my_list.clear()
23print(my_list)
24
25# reverse() : reverse the items
26my_list = ["banana", "cherry", "apple"]
27my_list.reverse()
28print('Reversed: ', my_list)
29
30# sort() : sort items in ascending order
31my_list.sort()
32print('Sorted: ', my_list)
33
34# use sorted() to get a new list, and leave the original unaffected.
35# sorted() works on any iterable type, not just lists
36my_list = ["banana", "cherry", "apple"]
37new_list = sorted(my_list)
38
39# create list with repeated elements
40list_with_zeros = [0] * 5
41print(list_with_zeros)
42
43# concatenation
44list_concat = list_with_zeros + my_list
45print(list_concat)
46
47# convert string to list
48string_to_list = list('Hello')
49print(string_to_list)
50