Aug 30, 2010

More on python

For loop
a=['cat','window','home']
for x in a:
print x, len(x)
This will give the length of each text in the array of a.
The output will be like;
cat 3
window 6
home 4

range() -
This gives a numarical like
range(5)
[1,2,3,4,5]
but if you use as:
range(10,15)
Ti will give the output as
[10,11,12,13,14]
But it will give the output only upto 14.

break and cnntinue
for n in range(2,10)
for x in range(2,n)
if n%x ==0:
print n,'equals',n,'*',n/x
break

pass statment
It do nothinmg. We can yous it to create delay loops.
while true
pass

Default argument values
def ask_ok(prompt,retries=4,complaint='yes or no, please !'):
while true:
ok =row_input(prompt)
if ok in ('y','ye','yes'):
return true
if ok in ('n','no','nop','nope'):
return false
retries=retries-1
i fretries <0
raise IOError('refusnik user')
print complaint

No comments:

Post a Comment

Your comments are always welcome ...