【发布时间】:2021-04-23 14:11:29
【问题描述】:
class Student:
def __init__(self, chemistry, english, math):
self.chemistry = chemistry
self.english = english
self.math = math
def chemistry(self):
return self.chemistry
def english(self):
return self.english
def math(self):
return self.math
def tot(self):
return self.chemistry + self.english + self.math
answer = Student(100,20,30)
answer.tot()
print(answer.tot())
我想知道如何在一个变量中获得 3 个输入。我尝试过使用“列表”,但没有成功。
【问题讨论】:
-
你怎么知道它不起作用?请参阅How to Ask 以及如何创建minimal reproducible example。
-
当你有一个同名的成员函数和一个属性时会发生什么?
标签: python class variables input