Some basic newbie questions...
jonathan.beckett
jonathan.beckett at gmail.com
Thu Dec 28 13:35:38 EST 2006
> Too many misconceptions here (I changed to a more PEP-8 style naming):
>
> class Gun(object):
> def __init__(self):
> self.shells = 10
>
> class Battleship(object):
> def __init__(self):
> self.guns = [Gun(), Gun()]
>
> def getShellsLeft(self):
> numShells = 0
> for aGun in self.guns:
> numShells += aGun.shells
> return numShells
>
> theBizmark = Battleship()
> print theBizmark.getShellsLeft()
Excellent example - once upon a time I used to write very neat code
indeed, but exposure to C# had pretty much knackered that (where all
the framework object methods are capitalized).
More information about the Python-list
mailing list