[問題] 新手f-string問題
大家好
小弟新手
最近看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>
想請教大家,問題是出在哪裡?
在此先謝謝了!
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 211.22.165.64 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Python/M.1623993567.A.C0A.html
→
06/18 13:47,
3年前
, 1F
06/18 13:47, 1F
→
06/18 15:02,
3年前
, 2F
06/18 15:02, 2F
→
06/18 15:02,
3年前
, 3F
06/18 15:02, 3F
推
06/18 16:35,
3年前
, 4F
06/18 16:35, 4F
推
06/18 16:38,
3年前
, 5F
06/18 16:38, 5F
→
06/18 16:40,
3年前
, 6F
06/18 16:40, 6F
推
06/18 16:45,
3年前
, 7F
06/18 16:45, 7F
推
06/18 16:48,
3年前
, 8F
06/18 16:48, 8F
推
06/19 09:04,
3年前
, 9F
06/19 09:04, 9F
→
06/19 21:24,
3年前
, 10F
06/19 21:24, 10F
→
06/20 01:01,
3年前
, 11F
06/20 01:01, 11F
推
06/20 03:24,
3年前
, 12F
06/20 03:24, 12F
推
06/20 14:53,
3年前
, 13F
06/20 14:53, 13F
推
06/21 11:41,
3年前
, 14F
06/21 11:41, 14F
推
06/21 11:43,
3年前
, 15F
06/21 11:43, 15F
→
06/21 11:44,
3年前
, 16F
06/21 11:44, 16F
→
06/21 11:45,
3年前
, 17F
06/21 11:45, 17F
→
06/21 11:46,
3年前
, 18F
06/21 11:46, 18F
→
06/21 11:46,
3年前
, 19F
06/21 11:46, 19F
→
06/21 11:46,
3年前
, 20F
06/21 11:46, 20F
→
06/21 11:47,
3年前
, 21F
06/21 11:47, 21F
→
06/21 11:47,
3年前
, 22F
06/21 11:47, 22F
→
06/21 11:47,
3年前
, 23F
06/21 11:47, 23F
→
06/21 11:48,
3年前
, 24F
06/21 11:48, 24F
→
06/21 11:49,
3年前
, 25F
06/21 11:49, 25F
→
06/21 11:50,
3年前
, 26F
06/21 11:50, 26F
→
06/22 08:46,
3年前
, 27F
06/22 08:46, 27F
→
06/24 04:26,
3年前
, 28F
06/24 04:26, 28F
推
06/25 01:25,
3年前
, 29F
06/25 01:25, 29F
→
06/25 01:25,
3年前
, 30F
06/25 01:25, 30F
→
06/26 04:54,
3年前
, 31F
06/26 04:54, 31F
→
06/26 04:54,
3年前
, 32F
06/26 04:54, 32F
推
06/26 06:55,
3年前
, 33F
06/26 06:55, 33F
→
06/26 20:33,
3年前
, 34F
06/26 20:33, 34F
→
06/29 02:14, , 35F
06/29 02:14, 35F
→
06/29 02:14, , 36F
06/29 02:14, 36F
推
06/29 07:49, , 37F
06/29 07:49, 37F
Python 近期熱門文章
PTT數位生活區 即時熱門文章