Exercise 8: Lists

In Python you define a list using brackets.  An empty list would simply be list = [].  A list can have any number of elements. To access a list  add the id between the brackets, such as list[0], list[1] and so on.

Type the code below and run it:

#!/usr/bin/python
 
list = [ "New York", "Los Angles", "Boston", "Denver" ]
 
print(list)     # prints all elements
print(list[0])  # print first element

list2 = [1,3,4,6,4,7,8,2,3]

print(sum(list2))
print(min(list2))
print(max(list2))
print(list2[0])
print(list2[-1])

Related: Complete Python Bootcamp: Go from zero to hero in Python

Exercise 7: Functions
Exercise 9: Dictionary