00:00:00 iterate forwards
00:01:39 iterate backwards
00:02:15 step
00:02:44 iterate over a string
00:03:26 continue
00:04:19 break
00:04:35 conclusion
for loops = execute a block of code a fixed number of times.
You can iterate over a range, string, sequence, etc.
------------- EXAMPLE 1 -------------
for x in range(1, 11):
print(x)
------------- EXAMPLE 2 -------------
for x in reversed(range(1, 11)):
print(x)
print("Happy New Year!")
------------- EXAMPLE 3 -------------
for x in range(1, 11, 2):
print(x)
------------- EXAMPLE 4 -------------
credit_card = "1234-5678-9012-3456"
for x in credit_card:
print(x)
------------- CONTINUE -------------
for x in range(1, 21):
if x == 13:
continue
else:
print(x)
------------- BREAK -------------
for x in range(1, 21):
if x == 13:
break
else:
print(x
On this page of the site you can watch the video online For loops in Python are easy 🔁In python tutorial with a duration of hours minute second in good quality, which was uploaded by the user NitCode 13 November 2022, share the link with friends and acquaintances, this video has already been watched 12 times on youtube and it was liked by 3 viewers. Enjoy your viewing!