test class

Run Settings
LanguagePython
Language Version
Run Command
#!/usr/bin/python3 # coding=utf-8 __author__ = 'iHook1Girl' print(__author__) from dio import * people = People('zhangsan',18,'',6000) print(people) print(people.name) # private property can't access outside # print(people.__salary) # but in praticle,we also access private property outside in another way # eg: as the following,but don't do that as well as possible print(people._People__salary) people.age = 20 print(people.age) people.setAge(22) print(people.getAge()) # people.setAge(-1) programmer = Programmer('iHook1Girl',17,8000) print(programmer) print(programmer.__doc__) print(programmer.__class__)
#!/usr/bin/python3 # coding=utf-8 __author__ = 'iHook1Girl' class People: 'info about class' # name = '' # age = 0 # work = '' def __init__(self,name,age,work,salary): self.name = name self.age = age self.work = work self.__salary = salary def getName(self): return self.name def getAge(self): return self.age def setAge(self,age): if 0<= age <= 200: self.age = age else: raise ValueError('age is not in range') def __str__(self): class_dic = { 'name':self.name, 'age':self.age, 'work':self.work, 'salary':self.__salary } ret = '{' for k,v in class_dic.items(): ret += '"'+k+'":'+str(v)+',' return ret[0:-1]+'}' class Programmer(People): ''' people who' work are coding ''' def __init__(self,name,age,salary): People.__init__(self,name,age,'coding',salary)
Editor Settings
Theme
Key bindings
Full width
Lines