A question regarding string instance uniqueness in python

前端 未结 4 1768
一个人的身影
一个人的身影 2020-12-21 08:37

I was trying to figure out which integers python only instantiates once (-6 to 256 it seems), and in the process stumbled on some string behaviour I can\'t see the pattern i

4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-21 09:00

    I believe short strings that can be evaluated at compile time, will be interned automatically. In the last examples, the result can't be evaluated at compile time because str or join might be redefined.

提交回复
热议问题