what does ` ` do in ' '.join([`x * x` for x in range(1, 6)])?
wuwei23 at gmail.com
Sat Sep 27 05:22:09 CEST 2008
On Sep 27, 12:39 pm, process <circularf... at gmail.com> wrote:
> ' '.join([`x * x` for x in range(1, 6)])
> exactly what does this symbol do and what does it stand for?
`<object>` is the same as repr(<object>). I'm pretty sure the backtick
operator has been removed from 3.0.
In the context of the code sample you posted, it appears to be used to
convert the result of x*x into a string for the join method, but I
personally think it's a misuse of repr() and think a call to str()
would be more appropriate:
>>> ' '.join((str(x * x) for x in range(1,6)))
'1 4 9 16 25'
More information about the Python-list