Python is the difference in the ==

Foreword

First, we know that in the high-level Python Python一切皆对象and three features of the object, identity (id), type (type), value (value). Let's talk about the specific difference is with the ==.

==Python is the standard operators in comparison operators, for comparison determination value (value) of the two objects are equal.
As shown below:
==
isalso known as the identity operator, the operator determines that the comparison between the object unique identifier, id is determined whether or not the same.
Examples are as follows:

>>> a = b = '无梦生7'
>>> c = '无梦生7'
>>> id(a)
1799814391920
>>> id(b)
1799814391920
>>> id(c)
1799814392400
>>> a == b
True
>>> a == c
True
>>> a is b
True
>>> a is c
False

From the above example, we can see a memory address (id) and b identical so a b IS result is True, with the c different from a so IS result is False c

to sum up

== determination value (value) of the two objects are equal

id is determined whether the same

Published 29 original articles · won praise 19 · views 1321

Guess you like

Origin blog.csdn.net/s1156605343/article/details/104396118