Code basics

David Arnold arnold at dstc.edu.au
Fri Mar 17 16:28:27 CET 2000


-->"JJ" == JJ  <joacim at home.se> writes:

  JJ> I'm a C/C++/Java programmer and wonder how to make "code blocks"
  JJ> in Python. Please translate this to Python:

you use indentation.

i'll assume that you want this in a method, but it could easily be a
simple function if you'd rather.

class Foo:
    """A sample class."""

    def Method(self):
        """A sample method."""

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


    def getNumberOfSomething(self):
        """The undefined method."""

        return 10
    

note that this will die at runtime because notDone is not defined.






More information about the Python-list mailing list