Logical values of objects in Python __python

Source: Internet
Author: User
None in Python, False, empty string "", 0, empty list [], empty Dictionary {}, NULL tuple () logical value is False, that is:
[Python] <strong>not None = = not False = = not ' = = not 0 = not [] = not {} = Not () </strong>
So when using a list, if you want to differentiate between x==[] and x = = None Two, use the not logical operator to determine whether an object is an empty list, a ganso, a dictionary, and whether the object is none with the member operator is or not

Not x means equivalent to if X is false, then True, else false

x = [] If not x:print (' x is empty ')
y = None if Y is none:      print (' Y are none ') = = is the equivalence of two objects. and is to determine whether two objects are the same object, that is, their IDs are consistent. IS and = = difference: is used to determine whether two variable reference objects are the same, = = to determine whether the value of a reference variable is equal. >>>  a   =   [1,   2,   3] >>>   b   =   a >>> &nbs P b   is   a True >>>   b   =   A True >>>   b   =   A [:] > >>   B   is   a False >>>   b   =   a True

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.