问题遇到的现象和发生背景
写python的时候遇到了这样的一个报错:
init() missing 2 required positional arguments: 'name' and 'age'
用代
class Student:
count = 0
def printnum(self):
print('count={}'.format(self.count))
def __init__(self,name,age):
self.name = name
self.age = age
def printstu(self):
print('name={},age={}'.format(self.name,self.age))
if __name__=='__main__':
s1 = Student()
s2 = Student('Tom','18')
print('s1.count={}'.format(s1.count))
s1.printnum()
s1.count='hello'
print('Student.count={}'.format(s1.count))
s2.printstu()
print('name={} age={}'.format(Student.name,Student.age))
```码块功能插入代码,请勿粘贴截图
###### 运行结果及报错内容
预期输出: s1.count=0
count=0
Student.count=hello
s2.name=Tom,s2.age=18
name=Tom age=18
实际输出:
```python
Traceback (most recent call last):
File "src/step1/pratise_1.py", line 12, in <module>
s1 = Student()
TypeError: __init__() missing 2 required positional arguments: 'name' and 'age'
我的解答思路和尝试过的方法
百度搜过,但是没有结果
我想要达到的结果
帮我解答一下这个报错的出现原因