![]() |
loops
hello im trying to figure out how to specify which code is part of the loop and which is not, on the tutorial im reading it says to indent the code, but is there any other better way to do it.
|
No. In Python, code blocks are defined by their indentation.
|
As far as I know it is the only way...
That's just python. There is no 'end of loop' statement! U' get used to it! |
If your statement block is short, you can do it all on one line:
:
for x in range(1, 11): x *=3; print xHi Fred! |
If you are looping for the purpose of building a list, read up on list comprehensions. Here is a quick way to build a list of the odd numbers up to 20:
:
print [c for c in range(20) if c%2 ] |
| All times are GMT -5. The time now is 2:04 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC