1# Method Description
2# append() Adds an element at the end of the list
3# clear() Removes all the elements from the list
4# copy() Returns a copy of the list
5# count() Returns the number of elements with the specified value
6# extend() Add the elements of a list (or any iterable), to the end of the current list
7# index() Returns the index of the first element with the specified value
8# insert() Adds an element at the specified position
9# pop() Removes the element at the specified position
10# remove() Removes the first item with the specified value
11# reverse() Reverses the order of the list
12# sort() Sorts the list
13# Note: Python does not have built-in support for Arrays, but Py# Method Description
14# append() Adds an element at the end of the list
15# clear() Removes all the elements from the list
16# copy() Returns a copy of the list
17# count() Returns the number of elements with the specified value
18# extend() Add the elements of a list (or any iterable), to the end of the current list
19# index() Returns the index of the first element with the specified value
20# insert() Adds an element at the specified position
21# pop() Removes the element at the specified position
22# remove() Removes the first item with the specified value
23# reverse() Reverses the order of the list
24# sort() Sorts the list
1#Creating lists
2my_list = ['foo', 4, 5, 'bar', 0.4]
3my_nested_list = ['foobar', ['baz', 'qux'], [0]]
4
5#Accessing list values
6my_list[2] # 5
7my_list[-1] # 0.4
8my_list[:2] # ['foo', 4, 5]
9my_nested_list[2] # ['baz', 'quz']
10my_nested_list[-1] # [0]
11my_nested_list[1][1] # 'qux'
12
13#Modifying lists
14my_list.append(x) # append x to end of list
15my_list.extend(iterable) # append all elements of iterable to list
16my_list.insert(i, x) # insert x at index i
17my_list.remove(x) # remove first occurance of x from list
18my_list.pop([i]) # pop element at index i (defaults to end of list)
19my_list.clear() # delete all elements from the list
20my_list.index(x[, start[, end]]) # return index of element x
21my_list.count(x) # return number of occurances of x in list
22my_list.reverse() # reverse elements of list in-place (no return)
23my_list.sort(key=None, reverse=False) # sort list in-place
24my_list.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'>
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)
1#Creating lists
2my_list = [1, "Hello", 3.4, 0, "World"]
3my_nested_list = [['Hello', 'World'],[47,39]]
4
5#Accessing lists
6my_list[1] # Hello
7my_list[-2] # 0
8my_list[:3] # [1, "Hello", 3.4]
9my_nested_list[1] #[47,39]
10my_nested_list[0][1] # World