Summarize the use of logical operators in Python

Source: Internet
Author: User
The following table lists the logical operators supported by all Python languages. Assuming that variable a holds 10 and variable B holds 20, then:

Example:

Try the following example to understand that all Python programming languages provide logical operators:

#!/usr/bin/pythona = 10b = 20c = 0if (A and B):  print "line 1-a and B is true" else:  print "line 1-either a Is isn't true or B is not true "if (A or B):  print" line 2-either A was true or B is true or both is true "else:  P Rint "Line 2-neither A is true nor B was true" a = 0if (A and B):  print "line 3-a and B is true" else:  print " Line 3-either A isn't true or B is not true "if (A or B):  print" line 4-either A was true or B is true or both AR E true "else:  print" line 4-neither A are true nor B is true "if not (A and B):  print" line 5-either A is not tr UE or B is not true "else:  print" line 5-a and B is true "

When executing the above program it produces the following result:

Line 1-a and B being Trueline 2-either A is true or B is true or both be Trueline 3-either A is isn't true or B is not Trueline 4-either A is true or "B is true" or both is Trueline 5-either "is" not true or "B is" not 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.