1#x starts at 1 and goes up to 80 @ intervals of 2
2for x in range(1, 80, 2):
3 print(x)
1for i in range(5):
2 print(i)
3# Output:
4# 0
5# 1
6# 2
7# 3
8# 4
9my_list = ["a", 1, True, 4.0, (0, 0)]
10for i in my_list:
11 print(i)
12# Output:
13# a
14# 1
15# True
16# 4.0
17# (0, 0)
1# Python for Loops
2
3# There are 2 types of for loops, list and range.
4
5# List:
6
7food = ['chicken', 'banana', 'pie']
8for meal in food: # Structure: for <temporary variable name> in <list name>:
9 print(meal)
10 # Will use the temporary variable 'meal' every time it finds an item in the list, and print it
11 # So output is: chicken\nbanana\npie\n
12# Range:
13for number in range(9): # Will loop 9 times and temporaray variable number will start at 0 and end at 8
14 print(number) # Prints variable 'number'
1print(range(4))
2>>> [0,1,2,3]
3print(range(1,4))
4>>> [1,2,3]
5print(range(2,10,2))
6>>> [2,4,6,8]
7