In python, is there a difference between repr
and the backquote `
(left of 1)?
For demonstration:
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'
Do the backquotes just call repr
? Is it simply for convenience? Is there any significant speed difference?
Thanks!
They're an alias for repr
. They have the exact same effect.
However, they're deprecated and have been removed in Python 3. Don't use them; use repr
.
According to python.org covering repr:
This is the same value yielded by conversions (reverse quotes).
It should be noted that the backtick method is considered something of an abomination by the language designers at the moment, and it was removed in python 3.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With