04 April 2018

Python For Loop Example: This Is What Professionals Do

python loops

The for loop you need is to print the data you want usually multiple times. For loop, is having two arguments such as variable name and in. I have also given video example in the bottom.

For loop Syntax:
for count in[1, 2, 3]: 
print(count)
print(’Yes’*count) ```
First step, How the above syntax works is what I want to share with you. The 'in' represents input array for Python for loop. That means the for loop works 3 times in Python. It displays only 3 times. The third step is just give 'yes', which will multiply with 'count' for 3 times.
This is whole story of for loop in Python. Second step, print just displays values of input that stored in the for loop variable of 'count'. The 'count' gets values one by one from for loop input array.

When you used the Shell to enter a loop, there was a reason that the interpreter waited to respond until after you entered an empty line: The interpreter did not know how long the loop block was going to be! The empty line is a signal tothe interpreter that you are done with the loop block.

Video Tutorial

I have created a small video, so that you can play quickly and check how for loop works in Python.
Also read

No comments:

Post a Comment

Thanks for your message. We will get back you.

Featured post

10 top Blockchain real features useful to financial projects

Blockchain is basically a shared ledger and it has many special features. Why you need it. Business transactions take place every second...

Most Viewed