[Tutor] class variables

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Wed Jun 23 15:57:10 EDT 2004



On Thu, 17 Jun 2004, Nick Lunt wrote:

> 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.


Hi Nick,

In this particular example, 'cans' is a local variable, so it lasts for
just the method call.


Hope this helps!





More information about the Tutor mailing list