Aug 30, 2010

More on python

For loop
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
but if you use as:
Ti will give the output as
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

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

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
i fretries <0
raise IOError('refusnik user')
print complaint

No comments:

Post a Comment

Your comments are always welcome ...