Python Fundamentals

For Loop in Python

In order to get for loop in python understood, we need to understand what is loop first

Loop is a sequence of statements, that gets repeating till our specified process is done

and there is a dangerous definition you should know about is infinity loops

that means loop won’t stop like loop has a purpose will never be done so program will never get out from it

For Loop in Python Syntax

for loop in python checks if last element reached

for loop in python has simple syntax, let’s see

for value_iterating in sequence:
list1 = ['Sarah', 'Moly', 'Johanna', 'Philippa', 'Sam', 'Dan', 'Alex']
for name in list1:
   print('Current name is: ' + name)

For Loop in Python With Else

we were dealing with else before in python if elif else so it’s not new, but when it gets executed

it happens when for loop job is done..

cars = ['Nissan', 'BMW', 'Ferrari']
for i in cars:
    print('No cars left')

How To Think Like For Loop in Python

Natasha want to hire new assistant with weight of 60 kilograms

so she announced on news_papers that statement and got list of girls who want the job

she got the list and set the variables as follows

weight = 93
purpose = 60
punish_her = ” sorry, you are fat girl “

and gonna tell her program to check if weight = purpose then exit if not then get punish_her printed till the condition comes true

for loop in python and simply how it works

Write a Comment

Your email address will not be published. Required fields are marked *