码迷,mamicode.com
首页 > 编程语言 > 详细

Python:对象的增删改查

时间:2018-09-23 18:11:13      阅读:201      评论:0      收藏:0      [点我收藏+]

标签:__init__   def   zha   class   delattr   set   +=   pytho   gen   

class Person:
number = 0
def __init__(self,name,gender,age):
self.name = name
self.gender = gender
self.age = age
Person.number+=1
def displayPerson(self):
print(‘name:‘,self.name,‘Gender:‘,self.gender,‘Age:‘,self.age)
def displayNumber(self):
print(‘Total person:‘,Person.number)
stu1 = Person(‘Liming‘,‘M‘,19)
stu2 = Person(‘Zhangli‘,‘F‘,20)
setattr(stu1,‘score‘,90)
print(getattr(stu1,‘score‘))
print(‘The score of the first student:‘,stu1.score)
delattr(stu1,‘score‘)
print(hasattr(stu1,‘score‘))

Python:对象的增删改查

标签:__init__   def   zha   class   delattr   set   +=   pytho   gen   

原文地址:https://www.cnblogs.com/Osword/p/9693024.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!