Python - While For and If Syntax

Python - While and For Loops and If Conditions


Note:- Pay attention to spaces and indentation in Python. Each indentation indicates sub-statement to the previous statement like shown below :-

Use # for comments

Loops


While Syntax:-

counter =0
while(counter <= 5) :
    print("counter",counter)
    counter+=1
# end loop


For Syntax:-

for a in (1,2,3,5,7,8,9):
    print(a)

If Condition

If Syntax:-

if expression:
  statements
  .
  .
elif:
  .
else:
  .






Comments