in
keyword, which can be used to check if a particular
value is in a list, or to loop over the elements one at a time:
numbers = [6, 8, 2, 9, 7] print(6 in numbers) # True print(0 in numbers) # False for number in numbers: print(number) # prints 6, 8, 2, 9, 7
range
and len
functions to loop over the list indexes, which is needed when changing
the values in a list:
numbers = [6, 8, 2, 9, 7] for i in range(len(numbers)): numbers[i] = numbers[i] ** 2 print(numbers) # [36, 64, 4, 81, 49]
Your code
Your code
numbers = [1, 2, 3, 4, 5, 6] # start of loop here print(number / 2)
Your code
names = ["James", "Nicole", "Helen", "Troy"]
Your code
numbers = [1, 2, 3, 4, 5] # start of loop here numbers[i] = numbers[i] * 2 print(numbers)
Your code
names = ["James", "Nicole", "Helen", "Troy"]
Your code