In the study of the class, there will inevitably be many questions, C Forum and blog Park master such as clouds (do not know is not also beautiful like clouds),
This blog post is a description of Python's class variables and instance variables! Just under the self.***. This form of the instance becomes
Quantity is not very understanding, take to share with gentlemen!
C Blog of the Big Gamma: http://blog.csdn.net/xxkkff/article/details/4396895
Previous "Class not Class 2": http://www.cnblogs.com/Ruby517/p/5709558.html
The general class definition is written in this form
Class < category name >: < Statement >
But now we're more of a form of this inheritance class.
Class < category name >(parent class name): < Statement >
In fact, there is a class of multiple inheritance, we are interested to look at:
Description of the script house: http://www.jb51.net/article/42623.htm
------------------------------------------------------------------------------------------------
Cut to the chase and venture to change the code of the original author a little bit.
"__init__ () is generally placed under the self.*** of this form, is the instance variable"
Under the class name, variables outside the function are class variables, either self.__class_.*** or class names. * * * * "this form"
1 #Coding:utf-82 3 #In this notation, the first letter of the subclass test is capitalized, and the parent object cannot be capitalized4 classTest (object):5 6Count = 0#This count, it's called "class variables."7 8 def __init__(self):9 TenSelf.count = Count#This self.count is called an instance variable. One #Self.__class_ is used to obtain a variable of the corresponding class itself, that is, the class variable A #can also be written in test.count form. -Self.__class__. Count + = 1 - theA = Test (3) - PrintA.count -Output 3 - + PrintTest.count -Output 1 + Ab = Test (-1) at PrintB.count -Output-1 - - PrintTest.count -Output 2
point Me
From the above, the class variable is common to all instances of the class (that is, the object), so it is additive, and the result of adding 1 is passed to the next object each time.
To continue to understand the class, refer to:
"Class not Class 3": http://www.cnblogs.com/Ruby517/p/5724385.html
Class variables and instance variables for "Class not class two" Python