Comparison operators are to test the condition. The conditional operator result as boolean True or False.
This operator returns True if both the operands are equal.if both the left and the right operand are equal to each other.
a=10
b=10
result= a==b
print(result)⚙️ Output:
True
This operator returns True if the left operand is less than the right operand.
a=10
b=20
result= a<b
print(result)⚙️ Output:
True
This operator returns True if the left operand is greater than the right operand.
a=30
b=20
result= a>b
print(result)⚙️ Output:
True
This operator returns True if the left operand is less than or equal to the right operand.
a=10
b=20
result= a<=b
print(result)⚙️ Output:
True
This operator returns True if the left operand is greater than or equal to the right operand.
a=50
b=20
result= a>=b
print(result)⚙️ Output:
True
This operator returns True if both the operands are not equal.
a=50
b=20
result= a!=b
print(result)⚙️ Output:
True
a=20
b=20
result= a!=b
print(result)⚙️ Output:
False
Python relies on indentation (whitespace at the beginning of a line) to define scope in the code. Other programming languages often use curly-brackets for this purpose.
Syntax:
if condition :
statements-1
statements-2
.....
.....
statements-nExample:
a=20
b=20
if a==b:
print("A is Equals to B ")⚙️ Output:
A is Equals to B
Syntax:
if condition :
statements-1
statements-2
.....
.....
statements-n
else:
statements-1
statements-2
.....
.....
statements-nExample:
a=20
b=30
if a==b:
print("A is Equals to B ")
else :
print("B is Unequals to A ")⚙️ Output:
B is Unequals to A
a=50
b=30
if a>b:
print("A is greater than B")
else :
print("B is greater than to A ")⚙️ Output:
A is greater than B
The “ = ” is an assignment operator is used to assign the value on the right to the variable on the left.
The ‘==’ operator checks whether the two given operands are equal or not.
1️⃣ Write a program to check whether applicant is eligible for voting or not using if statement.
👁 Show Answer
num=int(input("Enter Number :"))
rem=num%2
if rem==0:
print("Given Number is Even")
else:
print("Given Number is Odd")2️⃣ Write a program to check whether entered number is even ir odd by using if-else statements.
👁 Show Answer
age=int(input("Enter Your age :"))
if age>=18:
print("You are eligible for Voting")
else:
print("You are not eligible for Voting")
