大家好
小弟新手
最近看O'relly自学python
做到一个练习题想请教大家
>>> class Laser:
def does(self):
return 'disintegrate'
>>> class Claw:
def does(self):
return'crush'
>>> class SmartPhone:
def does(self):
return 'ring'
>>> class Robot:
def __init__(self):
self.Laser=Laser()
self.Claw=Claw()
self.SmartPhone=SmartPhone()
def does(self):
return '''
My laser, to %s.
My claw, to %s.
My smartphone, to %s.'''% (
self.Laser.does(),
self.Claw.does(),
self.SmartPhone.does() )
>>> robbie = Robot()
>>> print(robbie.does())
结果是
My laser, to disintegrate.
My claw, to crush.
My smartphone, to ring.
请问我把它改成f-string后,最后面写成
>>> def does(self):
return f'''
I have many functions.
My laser can {self.Laser.does()}
My claw can {self.Claw.does()}
My smartphone can {self.SmartPhone.does()}
'''
却出现
My laser can <__main__.Laser object at 0x000001D36C7C7A30>
My claw can <__main__.Claw object at 0x000001D36C7C7A90>
My smartphone can <__main__.SmartPhone object at 0x000001D36C7C7310>
想请教大家,问题是出在哪里?
在此先谢谢了!