Wednesday, November 4, 2009

Python backticks

Backticks in Python is an operator that converts the enclosed expression into a string.

For example:

>>> print `2+3`
5
>>> print `[ 1,2,3 ]`
[1, 2, 3]



Note that I intentionally changed the formatting in the list example to show that the backtick operator evaluates the expression and prints a representation. The spacing after the comma in the output is different from how I had it formatted in the print statement.

No comments: