我第一次看到这个。我想知道是什么!r
在调用的代码的最后一行中,以便我可以搜索它。我在以下位置找到了这段代码:https://adamj.eu/tech/2020/08/10/a-guide-to-python-lambda-functions/
class Puppy:
def __init__(self, name, cuteness):
self.name = name
self.cuteness = cuteness
def __repr__(self):
return f"Puppy({self.name!r}, {self.cuteness!r})"
最佳答案
这是一个格式字符串 conversion flag告诉格式化程序调用 repr
在格式化字符串之前在对象上。
Three conversion flags are currently supported:
'!s'
which callsstr()
on the value,'!r'
which callsrepr()
and'!a'
which callsascii()
.
关于python - !r 叫什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63475529/