Popular Posts

Friday, August 28, 2020

Python Beginner: For Loop

 Hello, Developer!


Today, we will learn "For Loop". "For loop" repeats indented codes until ending of "In" condition and setting up some value range by "Range"command in "In" condition. You can use Strings, Lists, variables, numbers at "In" condition with "Range" command.


"For Loop" declaration and examples

for Variable in "Strings": # Example: for intro in "Welcome to the Python coding world!":

for Variable in List: # Example: for name in list_friends:

for Variable in range(value): # Example: for index in range(10):

for Variable in range(value_1, value_2) # Example: for index in range(5, 10): 


Here, I show full exercise codes and execution result as following.

for letter in "Dinosaur":
print(letter)

friends = ["Jim", "Karen", "Kevin"]
for name in friends:
print(name)

for index in range(10):
print(index)

for index in range(5, 10):
print(index)

friends = ["Jim", "Karen", "Kevin"]
for index in range(len(friends)):
print(friends[index])

for index in range(5):
if index == 0:
print("The first Interaction!")
else:
print("Not first interaction.")

Can you see the same result? Congratulations! Now you can use "For Loop" feature in Python programming. Hope you modify these codes for test and have good understanding of "For Loop" feature. This loop feature is frequently used in usual programming.


Alright, see you on next post, Python developer! 😊


No comments:

Post a Comment

Python - Web crawling exercises

Hello Python developer! How are you? Hope you've been good and had wonderful time with Python. There are 10 Python requests module exerc...