7 Lists: arrays

Lists

Lists are a method of storing data whilst a program is running

1
2
3
4
5
6
a=[3,4,5,6]
b=[7,8,9,]
c=a+b
d=['a','b','c']
print(c)
print(d)

A list with a for loop

1
2
3
4
5
6
coins =[10, 100, 20, 50, 5, 0, 0, 0, 0, 0]
total=0
for i in range(len(coins)):
    print(i, coins[i])
    total = total + (coins[ i])
print(total)

Slicing Lists

1