0
Difference between if, elif and else statements and when should I use them? (PYTHON)
I am new and was wondering because I couldn't find any good answers online so this was my last chance at getting my question answered đ.
4 Answers
+ 1
1.If
If you have one result on specific condition on variable
Ex-
if x=5 :
print("yes")
2.If else
If you have two result on two different condition on a variable
Ex-
if x>=5
print("yes")
else :
print("no")
3.If else if
It is used when your have more than 3 result on different conditions of variable.
Ex-
if x=1 :
print("yes")
else if x=2 :
print("yes")
else if x=3 :
print("yes")
else :
print("no")
+ 1
Thank you đ
0
If operator used in case when you need to process some logic on specified condition.
If.. else if used in case when you have at least 2 conditions and you need divide process according to this conditions. You can write many else if statements, as many as you need.
The else operator used (according to logic) to process all other condition cases not equal to defined. But if you need proceed only predefine condition else statement not need
0
I get it now thank you