How to Make a For Loop in Python

preview_player
Показать описание
This video explains the basics of for loops in Python including looping over lists, numerical ranges, the continue keyword and the break keyword.
Рекомендации по теме
Комментарии
Автор

# Loop over items in a list

characters = ["Goku", "Vegeta", "Gohan", "Piccolo"]

for character in characters:
# Code to run for each iteration of the loop
print(character)

# Loop over a range of numbers

for num in range(0, 11):
print(num)

# Skip loop iterations with "continue"

for num in range(0, 11):
if num % 2 == 0:
continue
print(num)

# Escape a loop with "break"

for num in range(0, 11):
if num > 5:
break
print(num)

DataDaft
Автор

So num is defined in the loop and the range is given to the loop.

nutzeeer
join shbcf.ru