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 😞.

3rd Sep 2020, 12:22 AM
C Pitt
C Pitt - avatar
4 Antworten
+ 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")
3rd Sep 2020, 1:35 AM
Divya Mohan
Divya Mohan - avatar
+ 1
Thank you 🙂
3rd Sep 2020, 1:36 AM
C Pitt
C Pitt - avatar
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
3rd Sep 2020, 6:28 AM
george
george - avatar
0
I get it now thank you
3rd Sep 2020, 1:01 PM
C Pitt
C Pitt - avatar