0 Comparison of python-4.3 objects in basic science

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.