[問題] str.format()

看板Python作者 (881 forever)時間9年前 (2015/11/13 01:43), 編輯推噓0(003)
留言3則, 2人參與, 最新討論串1/1
問個白癡問題 這是書本上的範例 在下面Point這個class裡,有定義一個 __repr__() 如下: def __repr__(self): return "Point({0.x!r}, {0.y!r})".format(self) 請問裡面的!r是啥意思阿? class Point: def __init__(self, x=0, y=0): self.x = x self.y = y def distance_from_origin(self): return math.hypot(self.x, self.y) def __eq__(self, other): return self.x == other.x and self.y == other.y def __repr__(self): return "Point({0.x!r}, {0.y!r})".format(self) def __str__(self): return "({0.x!r}, {0.y!r})".format(self) -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 203.67.77.232 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1447379039.A.8BA.html

11/13 09:58, , 1F
repr(0.x) repr(0.y)
11/13 09:58, 1F


11/14 16:02, , 3F
google://python format "!r"
11/14 16:02, 3F
文章代碼(AID): #1MHK1VYw (Python)