Wednesday, July 11, 2012

IDKTAP #3: Backticks

Did you know that quoting an expression using backticks is an alias for repr() in Python 2.x? That is, it prints the "representation" of the result of the expression, which is generally what you'd have to paste into your Python source file to produce that same object.

print `"Think, it ain't illegal yet!"`

They took this out in Python 3.

2 comments:

  1. Other than for code golf, I'm glad backticks as an alias for repr is gone in Python 3. It was a little too magical with too little benefit.

    ReplyDelete
  2. I agree that consistency is a beautiful thing... on the other hand, some of Python's quirks do give it a certain flavor and charm. On the gripping hand, this frees up the ` character to potentially do something more useful in a future Python version.

    ReplyDelete