python smyčky
#x starts at 1 and goes up to 80 @ intervals of 2
for x in range(1, 80, 2):
print(x)
jak používat pro smyčky python
#simple for loop to print numbers 1-99 inclusive
for i in range(1,100):
print(i)
#simple for loop to loop through a list
fruits = ["apple","peach","banana"]
for fruit in fruits:
print(fruit)
python pro smyčku
for num in range(5): # range(5) generates numbers from 0 to 4(inclusive)
print(num) # for each iteration num has value assigned by range function
smyčka v Pythonu
# A Sample Python program to show loop (unlike many
# other languages, it doesn't use ++)
# this is for increment operator here start = 1,
# stop = 5 and step = 1(by default)
print("INCREMENTED FOR LOOP")
for i in range(0, 5):
print(i)
# this is for increment operator here start = 5,
# stop = -1 and step = -1
print("\n DECREMENTED FOR LOOP")
for i in range(4, -1, -1):
print(i)