Question

I have recently come to understand that we can use the following as a shorthand for repr(x) in Python:

`x`

However, I have rarely seen this in practice. Is it considered to be bad practice or unpythonic? Or are there any other reasons for which it is rarely used?

Était-ce utile?

La solution

I don't think many people would argue that it's Pythonic especially since it's been removed from Python3

Prior to that, I would never use it in real code. The problem being that quite a few developers didn't know what it was for, and it's not very easy to search for.

There has also been a move in Python3 to have .__next__() method instead of .next() for iterators, which strengthens the idea that repr(x) calls x.__repr__() etc.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top