面向对象
class student: name=None def say_hi(self,msg): print(f"大家好呀,我是:{self.name},{msg}") stu=student() stu.name='fqs' stu.say_hi("我想死大家了")
#设计一个闹钟 class Clock: id=None #闹钟的序列号 price=None #价格 def ring(self): import winsound winsound.Beep(2000,3000) #构建2个闹钟对象并让其工作 clock1=Clock() clock1.id="003032" clock1.price=19.99 print(f"闹钟的序列号:{clock1.id},闹钟的价格{clock1.price}") clock1.ring() clock2=Clock() clock2.id="003033" clock2.price=29.99 print(f"闹钟的序列号:{clock2.id},闹钟的价格{clock2.price}") clock2.ring()