Comparison Operators in Python 3
In this program, we will learn about comparison operators in Python 3.
Before finding the Greater, Smaller or Equal Number. We have knowledge about Comparison Operators. There are different comparison operations in python like other programming languages like Java, C/C++, etc. Those Operators are given below:
- Equal to Operator (==): If the values of two operands are equal, then the condition becomes true.
- Not Equal to Operator (!=): If the values of two operands are not equal, then the condition becomes true.
- Greater than Operator (>): If the value of the left operand is greater than the value of the right operand, then the condition becomes true.
- Greater than equal to (>=): If the value of the left operand is greater than or equal to the value of the right operand, then the condition becomes true.
- Smaller than Operator (<): If the value of the left operand is less than the value of the right operand, then the condition becomes true.
- Smaller than equal to (<=): If the value of the left operand is less than or equal to the value of the right operand, then the condition becomes true.
Find the Largest number smaller than or equal to number
def greater_smaller(num1,num2):
if num1>num2:
return "num_1 is greater"
elif num2>num1:
return "num_2 is greater"
return "both are equal"
#Here we take a input from user at a time.User have to enter number like 12,23 or 21,32. #Number will be seperated by comma. Or you can take input simple like num1=input() and #num2=input()
num1,num2=input("enter your num1&num2 values:").split(",")
print(greater_smaller(num1,num2))
Output:
C:\Users\Pramod\PycharmProjects\pythonProject\venv\Scripts\python.exe C:/Users/Pramod/PycharmProjects/pythonProject/main.py
enter your num1&num2 values:12,23
num_2 is greater
Process finished with exit code 0
Recommended Post:
- Python Hello World Program
- Python Comment | Creating a Comment | multiline comment | example
- Python Dictionary Introduction | Why to use dictionary | with example
- How to do Sum or Addition in python
- Python Reverse number
- find the common number in python
- addition of number using for loop and providing user input data in python
- Python Count char in String
- Python Last Character from String
- Python Odd and Even | if the condition
- Python Greater or equal number
- Python PALINDROME NUMBER
- Python FIBONACCI SERIES
- Python Dictionary | Items method | Definition and usage
- Python Dictionary | Add data, POP, pop item, update method
- Python Dictionary | update() method
- Delete statement, Looping in the list In Python
- Odd and Even using Append in python
- Python | Simple Odd and Even number
Get Salesforce Answers