how to do a for loop in python code example
Example 1: pytho loops
for x in loop:
print(x)
Example 2: python loops
#x starts at 1 and goes up to 80 @ intervals of 2
for x in range(1, 80, 2):
print(x)
Example 3: python for loop
for x in (list):
print(x)
Example 4: python loop
# A loop is used to iterate over a sequence
# The format of a loop is
for variable in object:
pass
# A common use of a for loop is using the range() function
for num in range(1, 10):
print(num)
# It can also be used with a list
new_list = ["Number 1", "Number 2", "Number 3", "Number 4"]
for x in new_list:
print(x)
Example 5: python for loop
for i in range(3):
print(i)
#prints: 0,1,2
Example 6: python for loop
a = 10
for i in range(1, 10) # the code will move from the range from 1 to 10 but not including 10
print(i)