for cycle in python code example
Example 1: python for in for in
adj = ["red", "big"]
fruits = ["apple", "banana"]
for x in adj:
for y in fruits:
print(x, y)
#output: red apple, red banana, big apple, big banana
Example 2: 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)
Example 3: for in python
# how to use for in python for (range, lists)
fruits = ["pineapple","apple", "banana", "cherry"]
for x in fruits:
if x == "apple":
continue
if x == "banana":
break
print(x)
# fron 2 to 30 by 3 step
for x in range(2, 30, 3):
print(x)
Example 4: python for loop
nums = ['one', 'two', 'three']
for elem in nums:
print(elem)