Python:’是’和’==’之间有什么区别?

Python: what difference between 'is' and '=='?

本问题已经有最佳答案,请猛点这里访问。

我正在尝试下一个代码:

1
2
3
4
5
6
7
x = 'asd'
y = 'asd'
z = input() #write here string 'asd'. For Python 2.x use raw_input()
x == y # True.
x is y # True.
x == z # True.
x is z # False.

为什么我们在最后一个表达中有错误?


(P)EDOCX1…0…语言检查EDOCX1 6 is EDOCX1 commercial 7 commercial IFF EDOCX1 niplication 8 commercial and EDOCX1 commercial 9.Are the same object(they are both stored in the same memory address).(p)(P)EDOCX1通用语10:平等检查,通常由魔法方法EDOCX1拼写11个音标-I.E.、EDOCX1音标12是EDOCX1音标7,如果EDOCX1音标14,音标14,音标7。(p)(P)In your case specifically,pyton optimizes the two hardcoded strings into the same object(since strings are immutable,there's no danger in that).既然EDOCX1的英文字母1会创造出一个在运行中的打击,它不可能做到优化,也不可能创造一个新的目标。(p)


(P)EDOCX1 0/cnique checks not if the object are equal,but if the objects are actually the same object.自从EDOCX1发音以来一直以来你创造了一个新的斯特林(p)(P)Python creates one object for all occurrences of the same string逐字记录,that's why EDOCX1(p)