Code basics

Darrell darrell at dorb.com
Fri Mar 17 10:24:07 EST 2000


"JJ" <joacim at home.se> wrote in message
news:8ath59$c7i$1 at vg170.it.volvo.se...
> I'm a C/C++/Java programmer and wonder how to make "code blocks" in
Python.
>
> Please translate this to Python:
>
> while( notDone )
> {
>     int chip = this.getNumberOfSomething();
>     if (chip == 10 )
>     {
>         System.out.println("Tjohoo");
>     }
>     else
>     {
>         System.out.println("Oh no!");
>     }
> }
>

while notDone:
    chip = self.getNumberOfSomething()
    if chip == 10:
        print "Tjohoo"
    else:
        print "Oh no!"


NOTE: Indenting replaces the curly braces, so don't delete white space.
NOTE: self must be passed as the first parm of a method.

def jumpTheJavaGuy(self, parm1):
    """
    Doc string here
    """
    while notDone:
        ......


Once-you-try-the-snake-you-won't-go-back
--Darrell





More information about the Python-list mailing list