
# List is similar to an array

integer_list = [1, 2, 3]

heterogeneous_list = ["string", 0.1, True]

list_of_lists = [ integer_list, heterogeneous_list, [] ]

list_length = len(integer_list) 		# equals 3
list_sum = sum(integer_list) 			# equals 6

# You can get or set the nth element of a list with square brackets:

# x = range(10) 		# is the list [0, 1, ..., 9]

x = [0,1,2,3,4,5,6,7,8,9]

# Indexing a list:

zero = x[0] 		# equals 0, lists are 0-indexed
one = x[1] 		# equals 1
nine = x[-1] 		# equals 9, 'Pythonic' for last element
eight = x[-2] 		# equals 8, 'Pythonic' for next-to-last element
x[0] = -1 		# now x is [-1, 1, 2, 3, ..., 9]

# Slices:

first_three = x[:3] 			# Upto 3: [-1, 1, 2]
three_to_end = x[3:] 			# 3 and up: [3, 4, ..., 9]
one_to_four = x[1:5] 			# >= 1 and < 5 [1, 2, 3, 4]
last_three = x[-3:] 			# [7, 8, 9]
without_first_and_last = x[1:-1] 	# [1, 2, ..., 8]
copy_of_x = x[:] 			# independent copy: [-1, 1, 2, ..., 9]

# Note:
y = x		# Makes an ALIAS !!!

y[0] = 99
print(x)	# [99, 1, 2, 3, 4,5 ,6 ,7,8,9]
