What do backticks mean to the python interpreter: `num`

前端 未结 3 687
被撕碎了的回忆
被撕碎了的回忆 2020-11-28 03:51

I\'m playing around with list comprehensions and I came across this little snippet on another site:

return \'\'.join([`num` for num in xrange(loop_count)])
<         


        
3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-28 04:43

    My guess is that num doesn't define the method __str__(), so str() has to do a second lookup for __repr__.

    The backticks look directly for __repr__. If that's true, then using repr() instead of the backticks should give you the same results.

提交回复
热议问题