In this chapter we talk about the comparison of objects, we are divided into two parts:
1. Comparison of values
From what we see, the comparison of general values is achieved by using the = =, >, < Operators.
In addition, Python implements a number of comparison operators
2. Comparison of the object itself (reference comparison)
Python uses a reference call instead of a value call, so the object itself needs to use the IS keyword
Here are some examples of contrasts, but we see some strange phenomena, which is what we call a pit
For example: When two objects are shaping, Python uses the caching technique in a smaller range of numbers, so it appears a=1,b=1 but A is B, theoretically a is not B
Another example: The following two strings, AB comparison shows that the two are the same object, but from what we theoretically should not, which is mainly related to the beginning of the Python design, the string is immutable, when a string is established, if the subsequent establishment of the same, the first search for this string, The new variable name is then affixed to the object's count plus 1, so when comparing strings, the references are the same
Right here, thank you.
------------------------------------------------------------------
Click to jump 0 basic python-Catalogue
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
0 Comparison of python-4.3 objects in basic science