PYTHON_TIPS[6]-IS and = = Difference

Source: Internet
Author: User

is and = = difference /difference between IS and = =

For Python objects, there are id/type/value three characteristics, and in judging two equal is and = =, respectively, the object ID and value are judged, the following example can see the difference between the two,

1x = [1, 2, 3]2y = [1, 2, 3]3z =x4 Print('x ID is%d, y id was%d, z ID is %d'%(ID (x), id (y), id (z) ))5 #x ID is 52275016, y id was 13096648, z ID is 522750166 7 #is judge by id, = = Judge by value8 Print(x isY, X==y)#False, True9 Print(x isZ, x==z)#true, True

From the view of the results, X and Y values are the same, but the ID is different, and the values of x and Z are the same, that is, the two points to the same object, respectively, Y and Z and x equivalent comparison, the results can be seen, the ID of the same x and Z are statements, and the ID is different but the same value of

Reference links

http://blog.csdn.net/imzoer/article/details/8637408

Python_tips[6], is and = = = Difference

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.