Class Members: Fields, methods, properties
property is preceded by a function method with an adorner, forged into a field, called without parentheses ()
The purpose is to forge a method into a field, and the property is one of the methods, and the method can be modified to
field to access a method is a series of actions that return a result, the Access property is equivalent to its own
A trait, not an action.
Vim day7-5.py
#!/usr/bin/python#-*-coding:utf-8-*-class Person (object): def __init__ (self,name,age): self.name = name Self.age = Age def func (self): return ' 123 ' def proporty (): pass @property def att (self ): return ' 123 ' obj = person (' 1 ', 2) print Obj.nameprint obj.func () print Obj.att
Fields divided into normal fields and static fields
Vim day7-6.py
#!/usr/bin/python#-*-coding:utf-8-*-class Province (object): country = "China" #静态字段, there is memory inside def __init__ ( Self,name): self.name = name #普通字段, stored inside the object shanxi = province ("shanxi") Shangdong = Province ("shandong") Henan = Province (" Henan ") Print ID (shanxi.country) Print ID (shangdong.country) print Shanxi.name
Python Object-oriented fields