In [ ]:
# looping - iterations/generators
# repeating a block of code n number of times
# for,do..while,while..do,until,foreach
# python - for,while
# for - finite loop
# while - infinite loop
In [1]:
# for
# iterators work on sequence.
my_string = "python" # sequence of characters
for value in my_string:
print "value - {}".format(value)
In [2]:
for training in ('python','linux','django','flask'):
print training
In [3]:
# range
print help(range)
In [7]:
print range(5) # 0 till 5 ; 5 not included.
print range(1,6)
print range(1,10,2)
print range(0,10,2)
In [9]:
for value in range(1,11):
print value
In [10]:
# iter
m = iter(range(1,6))
print m
In [11]:
print m.next()
In [12]:
print m.next()
In [13]:
print m.next()
In [14]:
print m.next()
In [15]:
print m.next()
In [16]:
print m.next()
In [17]:
# iterator
print range(1,6)
In [18]:
# generator
print help(xrange)
In [20]:
print xrange(1,6)
print type(xrange(1,6))
In [21]:
for value in xrange(1,6):
print value
In [ ]:
# range(1cr) -> you will run out of memory.
# xrange(1cr) -> you will run out of time.
In [ ]:
# https://projecteuler.net/archives
# https://github.com/sambapython/python