Member operators
Python has a member operator that can determine whether an element is in a sequence. For example, you can tell if a character belongs to the string, you can tell if an object is in the list, and so on.
The syntax for using member operators in Python is:
obj [not] in sequence
The return value of this operator is true or false.
Let's look at a code example:
Identity operator
Python supports the comparison of the object itself, and the syntax for comparison is:
is [not] obj2
The identity operator is used to compare whether 2 objects are the same object, while the = = in the previous comparison operator is used to compare the values of 2 objects for equality.
Here we need to tell you how the identity operator is judged.
The variables in Python have 3 properties: Name, ID, value.
Name can be understood as variable name, ID can be combined with memory address to understand, value is a variable. The IS operator is judged by this ID, which returns true as the ID, otherwise false.
Like what:
A = [1, 2, 3= [1, 2, 3]print(a = = b)print is b)
The result of this code output is true and false, because the value of variable A and variable B is the same, so the value of the variable is compared with the = = operator, so returns True. But when using is, the comparison is id,a and B's ID is different (can use ID (a) to see the ID of a), so return false.
But not all of this is true, for small integers, python caches all integers from 5 to 257, in total, 262. So the following code:
A= + = +printis =
Returns the result one is true, one is the same as above, and the result of true is that Python false,false small integers, and strings are the same, and using is will return equality.
More learning content, just in the code bud Net Http://www.mayacoder.com/lesson/index
Python Novice Learning Basics Operator--member operations and identity operations