jackfrued / Python-Core-50-Courses

Python语言基础50课

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

第11课 字符串is运算错误

Suny-02 opened this issue · comments

commented

第11课
s1 = 'hello world'
s2 = 'hello world'
s3 = s2

比较字符串的内容

print(s1 == s2, s2 == s3) # True True

比较字符串的内存地址

print(s1 is s2, s2 is s3) # False True

s1 is s2 会返回true
s1 s2 s3三个对象引用同一个字符串池