作业帮 > 综合 > 作业

python问题,我的function不能return,讲的是一个开关灯的类

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/25 08:51:32
python问题,我的function不能return,讲的是一个开关灯的类
class LightSwitch:
def __init__(self,condition):
self.is_on = condition
if not isinstance(condition,bool):
InvaildSwitchExpection = TypeError("it is not a right state".format(condition))
raise InvaildSwitchExpection
def turn_on(self):
self.is_on = True
def turn_off(self):
self.is_on = False
def filp(self):
if self.is_on == False:
self.is_on = True
else:
self.is_on = False
def __str__(self):
if self.is_on == True:
return "I am on"
else:
return "I am off"
这是第一个类,下面还有一个,那个which_switch不能return,return出来什么都没有
类里面定义的不是函数,而是方法.我没见过方法可以“return”.