A brief description of the difference between the keyword is and == in Python

  • 2020-04-02 13:51:54
  • OfStack

This article analyzes the difference between the keyword is and == in python with a simple example for your reference.

Let me begin by explaining a few of the small points related to Python learning.

An object in Python has three elements: id, type, and value
Where: id is used to uniquely identify an object, type identifies the type of the object, and value is the value of the object

Is determines whether an object a is an object b by id

== whether the value of object a is equal to the value of object b is determined by value

Specific examples are as follows:


>>> a=100
>>> b=100.0
>>> a is b
False
>>> a==b
True
>>> id(a)
30696848L
>>> id(b)
48685000L
>>> id(a)==id(b)
False

Related articles: