[Tutor] class variables
flaxeater at yahoo.com
Thu Jun 24 01:12:40 EDT 2004
> class beer:
> def __init__(self):
> self.make = 'murphys'
> cans = 4
> There's several examples I've seen where 'self.var' isn't used,
> 'var' is, as in 'cans' above.
> I know that each instance of 'beer' will have its own value for
> but what is the use of 'cans' without using self ?
this troubled me at first and I'm not sure but I may have asked this
very question here.
self.var in this case means that it's a class variable available to
the instance. In this case 'cans' is a function variable only
available to things inside that function. just like this
I hope this helps.
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
More information about the Tutor