On 21/09/12 02:57, eryksun wrote:
On Thu, Sep 20, 2012 at 12:25 PM, eryksun<eryk...@gmail.com>  wrote:

             cls._count += 1

I forgot the obligatory warning about class variables.

Python is not Java. In Python, classes are first-class objects (no pun
intended) and can be assigned to variables the same as any other type.

x = something_that_returns_a_float()  # x is a float variable
s = something_that_returns_a_string()  # s is a string variable
C = something_that_returns_a_class()  # C is a class variable

Preferred terminology is attribute, not variable. Class attributes live
in the class and are shared across all instances. Instance attributes
live in the instance and are not shared.


The subclass gets a shallow copy of the parent class namespace.

Not so much.

py> class C(object):
...     x = 1
...
py> class D(C): pass
...
py> D.__dict__ == C.__dict__
False
py> 'x' in D.__dict__
False




--
Steven
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to