Example illustrates the use of comparison operators in Python

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

For example:

Try the following example to understand the comparison operators available in all Python programming languages:

#!/usr/bin/pythona = 21b = 10c = 0if (A = = B):  print "line 1-a are equal to B" else:  print "line 1-a are not EQ UAL to B "if (A! = b):  print" line 2-a are not equal to B "else:  print" line 2-a are equal to B "if (a <> b):  print "line 3-a are not equal to B" else:  print "line 3-a are equal to B" if (A < b):  print "line 4 -A is less than B "else: print" line 4-a are not less than  than B "if (A > B):  print" line 5-a is greater than B "Else:  print" line 5-a isn't greater than B "a = 5;b = 20;if (a <= b):  print" line 6-a are either less t Han or equal to B ' else:  print ' line 6-a was neither less than nor equal to B ' if (b >= a):  print "Line 7- b is either greater than or equal to B "else:  print" line 7-b are neither greater than nor equal to B "

When executing the above program it produces the following result:

Line 1-a isn't equal to BLine 2-a are not equal to bLine 3-a are not equal to BLine 4-a are not less than BLine 5- A is greater than bLine 6-a are either less than or equal to BLine 7-b are either greater than or equal to B
  • 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.