大家好
小弟新手
最近看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>
想請教大家,問題是出在哪裡?
在此先謝謝了!