When we talk about storing multiple values in a container-like data structure, the first thing that comes to mind is a list.
You can initialize a list as:
arr = list() # or simply arr = 
or with a few elements as:
arr = [1,2,3]
Elements can be accessed easily similar to most programming languages:
print arr # result is 1 print arr + arr + arr # result is 6
Lists in Python are very versatile. You can add almost anything in a Python list.
In Python, you can create a list of any objects: strings, integers, or even lists. You can even add multiple types in a single list!
Let's look at some of the methods you can use on list.
Adds a single element
x to the end of a list.
arr.append(9) print arr # prints [1, 2, 3, 9]
Merges another list
L to the end.
arr.extend([10,11]) print arr # prints [1, 2, 3, 9, 10, 11]
x at position
arr.insert(3,7) print arr # prints [1, 2, 3, 7, 9, 10, 11]
Removes the first occurrence of element
arr.remove(10) arr # prints [1, 2, 3, 7, 9, 11]
Removes the last element of a list. If an argument is passed, that index item is popped out.
temp = arr.pop() print temp # prints 11
Returns the first index of a value in the list. Throws an error if it's not found.
temp = arr.index(3) print temp # prints 2
Counts the number of occurrences of an element
temp = arr.count(1) print temp # prints 1
Sorts the list.
arr.sort() print arr # [1, 2, 3, 7, 9]
Reverses the list.
arr.reverse() print arr # [9, 7, 3, 2, 1]