The summary focuses on the advantages of object-oriented, high scalability
The sample code is as follows:
1 classChinese:2 def __init__(self,name,age,sex):3Self.name=name4Self.age= Age5self.sex=Sex6 7 8P1 = Chinese ('Egon', 18,'male')9P2 = Chinese ('Alex', 38,'female')TenP3 = Chinese ('WPQ', 48,'female')
We insert a data property into the class, just add it to the class, and the object can be accessed without any changes, and the code is validated as follows:
1 classChinese:2Country =' China'3 def __init__(self,name,age,sex):4Self.name=name5Self.age= Age6self.sex=Sex7 8 9P1 = Chinese ('Egon', 18,'male')TenP2 = Chinese ('Alex', 38,'female') OneP3 = Chinese ('WPQ', 48,'female') A - Print(p1.country) - Print(p2.country) the Print(P3.country)
The results are as follows:
China
China
China certificate can be accessed
Insert a Function property, just add it in the class, the object can be accessed without any changes, and the code is validated as follows:
1 classChinese:2Country =' China'3 def __init__(self,name,age,sex):4Self.name=name5Self.age= Age6self.sex=Sex7 8 defEat (self):9 Print('%s is eating'%self.name)Ten One AP1 = Chinese ('Egon', 18,'male') -P2 = Chinese ('Alex', 38,'female') -P3 = Chinese ('WPQ', 48,'female') the - p1.eat () - p2.eat () -P3.eat ()
The results are as follows:
Egon is eating
Alex is eating
WPQ is eating
python--Object-Oriented summary