1. Distinction
in: On the one hand, it can be used to check whether there is a certain value in a sequence (list, range, string, etc.). It can also be used to traverse sequences in a for loop.
is: used to determine whether two variables are the same object. If the two objects are the same object, return True, otherwise return False. To distinguish it from ==, use the == operator to determine whether the two variables are equal.
2. Example
x = ["Zhang San","Li Si","Wang Wu"] "Zhang San" in x # ------------------------- for i in range(3): print(i)
Knowledge points expansion:
Three basic elements of python objects: id (identity identity), type (data type) and value (value).
is operator: The unique identity (id) between objects is judged.
== operator: It determines whether the value (value) between objects is the same, and the object's __eq()__ method is called.
in Member ID: Determine whether a single object is in a container.
The above is the detailed summary of the differences between in and is in Python. For more information on the distinction between in and is in Python, please pay attention to my other related articles!