
#python
Conditions in Python
Conditions are used in Python when we want our program to make a decision. They check whether something is TRUE or FLASE and then run the required code.
Python mainly uses if, elif, and else for conditions.
if Statement
The if statement runs a block of code when a condition is true.
age = 20
if age >= 18:
print("You are an adult")Output:
You are an adultelse Statement
else runs when the if condition is false.
age = 15
if age >= 18:
print("You are an adult")
else:
print("You are a minor")elif Statement
elif is used when we want to check more than one condition.
marks = 75
if marks >= 90:
print("Grade A")
elif marks >= 60:
print("Grade B")
else:
print("Grade C")Output:
Grade BComparison Operators
Conditions commonly use comparison operators such as:
== Equal to
!= Not equal to
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal toFor example:
age = 20
if age >= 18:
print("Eligible")Join Techsnap Creators
Share your knowledge and earn ??
Want to showcase your tech expertise and get rewarded for your insights? Join the Techsnap creator network!
Write insightful blogs, stay ahead of industry trends, and grow your professional brand while helping others in the community.
Ready to make an impact?

Comments