python之__str__用法
2021-01-17 22:17
标签:student core nan super %s div ini pre turn python之__str__用法 标签:student core nan super %s div ini pre turn 原文地址:https://www.cnblogs.com/zoulixiang/p/12915294.html 1 class Person(object):
2 def __init__(self,name,gender):
3 self.name = name
4 self.gender = gender
5
6 def __str__(self):
7 return ‘(Person: %s, %s)‘ %(self.name,self.gender)
8 __repr__ = __str__
9 p = Person(‘Bob‘,‘male‘)
10 #p = Person()
11 print(p)
12
13
14 class Persons(object):
15 def __init__(self,name,gender):
16 self.name = name
17 self.gender = gender
18
19 class Student(Persons):
20 def __init__(self,name,gender,score):
21 super(Student, self).__init__(name,gender)
22 self.score = score
23
24 def __str__(self):
25 return ‘(Student: %s, %s, %s)‘ %(self.name,self.gender,self.score)
26
27 s = Student(‘zou‘,‘nan‘,‘80‘)
28 print(s)
上一篇:braise脚本学习指引--braise语言基本介绍
下一篇:CSS