In [ ]:
# looping
# for,while .. do,do.. while,until,foreach # other programmign languges
# for,while # python
# for is a finite loop.
# while is not a finite loop,depends on condition.
In [1]:
# A for/while loop works on sequences
# A string is a sequence of characters.
my_string="python"
for value in my_string:
print value
In [2]:
for training in ['perl','shell','django','ruby']:
print training
In [3]:
# numbers
print help(range)
In [9]:
print range(5) # 0 till 4 , 5 not included
# for(i=1,i<=5,i++)
print range(1,5,1)
# for(i=2,i<=10,i+2)
print range(2,10,2)
for value in range(1,6):
print "hey hello"
In [10]:
# iteration
print help(iter)
In [12]:
print range(1,6),type(range(1,6))
m = iter(range(1,6))
print m,type(m)
In [13]:
print m.next()
In [14]:
print m.next()
In [15]:
print m.next()
In [16]:
print m.next()
In [17]:
print m.next()
In [18]:
print m.next()
In [20]:
# iterator and generator.
print help(range)
# Iterator ex: range
print range(1,5)
In [21]:
# generator ex: xrange
print help(xrange)
In [23]:
print xrange(5),type(xrange(5))
In [24]:
for value in xrange(5):
print value
In [ ]:
# iterator : memory consuming,run out of memory
# generator : time consuming,run out of time
In [ ]:
my_string="python"
# my_string = object/instance
# my_string.<anythong> = method(function)/data(variabel)