Skip to content

[Python] Tutorial(6) greater than, less than, equal to

Last Updated on 2021-04-08 by Clay

The previous we mentioned the "bool", and we simply teach the basically concept of "True" and "False".

If my tutorial have wrong content, please leave me a message below to let me know, thank you =)

I don't care I'm corrected, but I care I mislead anyone.

And then we start our tutorial today! Complete the logic of Python, today we will teach how to use "greater than", "less than", and "equal to".


greater than, less than, equal to

The just-in-time logic doesn't just have these, so you can take a look at a few of the items listed below:

  • greater than >
  • less than <
  • equal to ==
  • greater than or equal to >=
  • less than or equal to <=
  • not equal to !=
  • equivalent "is"
  • ...... etc

We will give a brief explanation of each symbol.


Greater than

# Greater than >
a = 1
b = 0

if a > b:
   print('a greater than b!')


Output:

a greater than b!

Less than

# Less than <
a = 0
b = 1

if a < b:
   print('a less than b!')


Output:

a less than b! 

Equal to

# Equal to ==
a = 1
b = 1

if a == b:
   print('a equal to b!')


Output:

a equal to b! 

Greater than or equal to

# Greater than or equal to >=
a = 2
b = 1

if a >= b:
    print('a greater than or equal to b!')

a = 1
if a >= b:
    print('a greater than or equal to b!')


Output:

a greater than or equal to b! 
a greater than or equal to b! 

I think I have to give an explain about this.

Originally, the "a" variable is set to 2, greater than or equal to 1. Then set the "a" variable to 1, and it also greater than or equal to 1.

So we print twice.


Less than or equal to

# Less than or equal to <=
a = 2
b = 2
c = 1

if b <= a:
    print('b less than or equal to a!')

if c <= a:
    print('c less than or equal to a!')


Output:

b less than or equal to a! 
c less than or equal to a! 

The variable "b" is equal to a.
The variable "c" is less than a.

So we also print twice.


Not equal to

# not equal to !=
a = 2
b = 1

if b != a:
    print('b not equal to a!')


Output:

b not equal to a!

This is very simple. The value of "a" is not equal to "b".


Above we complement the logic of Python.

I want to write some tends to use Python to do more with the tools I use in my life, maybe it is a little pet project.

I believe that will be very interesting.


References


Read More

Leave a ReplyCancel reply

Exit mobile version