[Tutor] trouble with if
Che M
pine508 at hotmail.com
Thu May 24 21:30:34 CEST 2007
>I'm not sure what the whole indentation thing is for. And now I'm having
>trouble with the if statement things.
Maybe your if statement troubles have been solved by others by now, but I'll
just add that "the indentation thing" is a vital feature of Python, it is
the way to separate code blocks. Other languages uses other means, like
curly braces, etc. I get the sense those who like Python enjoy indentation
because it forces the code to be quite readable, and I agree. See this:
http://www.diveintopython.org/getting_to_know_python/indenting_code.html
Also, as mentioned previously, keep in mind that 2 is not the same as "2"
and "=" is not the same as "==". The single "=" is used to assign names to
objects, whereas the == is for evaluating something, so for if statements
use == and not =. Also note you can put "and" along with if, so you can say
if x == "mom" and y == "dad":
print "my parents"
and lots of other stuff.
-Che
_________________________________________________________________
PC Magazines 2007 editors choice for best Web mailaward-winning Windows
Live Hotmail.
http://imagine-windowslive.com/hotmail/?locale=en-us&ocid=TXT_TAGHM_migration_HM_mini_pcmag_0507
More information about the Tutor
mailing list