标签:string false -- 相同 字符串 code aaaaa aaa class
? 字符串有时很棘手 *1.
>>> a = "some_string"
>>> id(a)
140420665652016
>>> id("some" + "_" + "string") # 注意两个id是相同的
140420665652016
2.
>>> a = "wtf"
>>> b = "wtf"
>>> a is b
True
>>> a = "wtf!"
>>> b = "wtf!"
>>> a is b
False
>>> a, b = "wtf!", "wtf!"
>>> a is b
True
3.
>>> ‘a‘ * 20 is ‘aaaaaaaaaaaaaaaaaaaa‘
True
>>> ‘a‘ * 21 is ‘aaaaaaaaaaaaaaaaaaaaa‘
False
有道理,对不对?
python每日一帖---难懂的现象+清楚的解释---棘手的字符串
标签:string false -- 相同 字符串 code aaaaa aaa class
原文地址:http://blog.51cto.com/13946759/2168751