Loops in python are just like the loops we use in C and other languages.
There are other special applications also for the loops in python.
For example we have just seen an else statement for an if statement but in Python we can have an else statement for a loop even.
Loops supported by Python:
There are other special applications also for the loops in python.
For example we have just seen an else statement for an if statement but in Python we can have an else statement for a loop even.
Loops supported by Python:
- for loop
- while loop
FOR LOOP
syntax:
>>>v = (1, 3, 5, 6, 7)
>>>for i in v:
........ print i
>>>for i in v:
........ print i
WHILE LOOP
The syntax of while loop is also almost the same like the one used in C language.
syntax:
>>> i=0
>>> while i<10:
... print i,
... i=i+1
...
0 1 2 3 4 5 6 7 8 9
>>> while i<10:
... print i,
... i=i+1
...
0 1 2 3 4 5 6 7 8 9






0 comments:
Post a Comment