Classic class, New class
Classic classes are those that do not inherit, and the new class is inherited. Now it's basically a new class.
#encoding =utf-8
#经典类
Class Dog:
Pass
#继承了object, for the new class
Class Dognew (object):
Pass
#可输出此类是什么类型的类
Print type (DOG)
Print type (dognew)
Class Heibei (Dog):
Pass
Class Bomei (dognew):
Pass
Print type (Heibei)
Print type (Bomei)
Results:
<type ' Classobj ' >
<type ' type ' >
<type ' Classobj ' >
<type ' type ' >
Method: Is the encapsulation of class behavior
Instance method: The Self keyword, which accesses instance properties through self, invokes an instance method
Special methods: Methods that the compiler automatically adds, the Self keyword (such as init)
static method: @staticmethod (Adorner)
Class method: @classmethod (Adorner)
The visibility of the property:
Common Properties: Properties that are used in classes and outside the class
Built-in properties: Attributes that are automatically added by the compiler, such as __dict__
Private properties: Properties that can only be used within the class, __, will be gaiminghuanxing, _, will not be renamed, symbolic meaning greater than the actual meaning.
#encoding =utf-8
class Person (object):
Pass
Class Chinese (person):
#定义类属性
Nation = ' China '
def __init__ (self, name, age, Sex):
#定义实例属性
Self.name = Name
Self._age = Age
Self.__sex = Sex
Zhangsan = Chinese (' Zhangsan ', ' Male ')
Print Zhangsan.name
Print Zhangsan._age
Print Zhangsan._chinese__sex
#print Zhangsan.__sex
Print dir (Chinese)
Results:
Zhangsan
18
Male
[' __class__ ', ' __delattr__ ', ' __dict__ ', ' __doc__ ', ' __format__ ', ' __getattribute__ ', ' __hash__ ', ' __init__ ', ' __ module__ ', ' __new__ ', ' __reduce__ ', ' __reduce_ex__ ', ' __repr__ ', ' __setattr__ ', ' __sizeof__ ', ' __str__ ', ' __ Subclasshook__ ', ' __weakref__ ', ' Nation ']
Python language Learning (iv) 1.1