Python for Loop Statements¶
In [1]:
""" It has the ability to iterate over the items of any sequence, such as a list or a string.
Syntax
for iterating_var in sequence:
statements(s)
"""
Out[1]:
In [3]:
"""
for letter in 'Python': # First Example
print 'Current Letter :', letter
fruits = ['banana', 'apple', 'mango']
for fruit in fruits: # Second Example
print 'Current fruit :', fruit
print "Good bye!"
"""
Out[3]:
In [6]:
for var1 in range(5):
print(var1)
In [7]:
range(5)
Out[7]:
In [8]:
print(range(5))
In [9]:
type(range(5))
Out[9]:
In [10]:
a=range(5)
type(a)
Out[10]:
In [11]:
print(a)
In [14]:
list(range(2,5))
Out[14]:
In [15]:
for i in range(5):
print("vlr training")
In [16]:
for i in range(5):
print("vlr training",i)
In [17]:
for i in range(5):
print("vlr training",i+1)
In [21]:
for i in range(2,10,2):
print("vlr training",i)
In [25]:
for i in 'VLR Training': # First Example
print ( i)
print("wel come")
In [26]:
a=["suresh","ramesh","venkat"]
a
Out[26]:
In [27]:
list(a)
Out[27]:
In [35]:
z=1
for i in a:
print (z," : ",i)
z=z+1
No comments:
Post a Comment