[Tutor] class variables

Nick Lunt nick at javacat.f2s.com
Thu Jun 17 18:42:02 EDT 2004


Hi folks,

Im making my way through the book 'Learning Python 2nd Edition'. I 
understand classes but I have a question.
Take the following for example -

class beer:
    def __init__(self):
       self.make = 'murphys'
       cans = 4

There's several examples I've seen where 'self.var' isn't used, just 
'var' is, as in 'cans' above.
I know that each instance of 'beer' will have its own value for 'make' 
but what is the use of 'cans' without using self ?

Any pointers in the right direction happily received :)

Regards
Nick.





More information about the Tutor mailing list