Python:repr 与反引号 [英] Python: repr vs backquote
本文介绍了Python:repr 与反引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在python中,repr
和反引号`
(1的左边)有区别吗?
In python, is there a difference between repr
and the backquote `
(left of 1)?
演示:
class A(object):
def __repr__(self):
return 'repr A'
def __str__(self):
return 'str A'
>>> a = A()
>>> repr(a)
#'repr A'
>>> `a`
#'repr A'
>>> str(a)
#'str A'
反引号只是调用 repr
吗?仅仅是为了方便吗?是否有明显的速度差异?
Do the backquotes just call repr
? Is it simply for convenience? Is there any significant speed difference?
谢谢!
推荐答案
它们是 repr
的别名.它们具有完全相同的效果.
They're an alias for repr
. They have the exact same effect.
但是,它们已被弃用并已在 Python 3 中删除.不要使用它们;使用 repr
.
However, they're deprecated and have been removed in Python 3. Don't use them; use repr
.
这篇关于Python:repr 与反引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文