Friday, 15 July 2016

For loop in Python

in general, statements are executed sequentially: The first statement in a function is executed first, followed by the second, and so on. There may be a situation when you need to execute a block of code several number of times.
Programming languages provide various control structures that allow for more complicated execution paths.
For Loop
for Loop is used to iterate a variable over a sequence(i.e., list or string) in the order that they appear.
Syntax:
for <variable> in <sequence>:
     Syntax of for Loop
for val in sequence:
    Body of for

Example for for loop as given below :
list1=[14,5,7,6,8,0,9]
for l in list1:
    print l
when this block of would be executed output would be as given below:
14
5
7
6
8
0
9
Softcrayons tech solutions is a Python Training institute in Ghaziabad.

No comments:

Post a Comment