|

楼主 |
发表于 2020-3-4 09:35:34
|
显示全部楼层
缩进问题是我手机编写的代码,实际代码如下,运行能输出,但是有个报错。
报错信息:
E:\sms\venv\Scripts\python.exe E:/sms/test11.py
hello china
Traceback (most recent call last):
File "E:/sms/test11.py", line 23, in <module>
print(s1)
TypeError: __str__ returned non-string (type NoneType)
- class StudentModel:
- """
- 学生数据模型类
- """
- def __init__(self, name, age, score):
- self.name = name
- self.age = age
- self.score = score
- def infos(self):
- m = 'hello china'
- print(m)
- def __str__(self):
- return self.infos()
- def __repr__(self):
- return 'hello world'
- s1 = StudentModel("zs", 29, 90)
- print(s1)
复制代码 |
|