+ 1

Elif or else : if ?

what is the difference between elif and else: if

14th Jan 2017, 10:22 PM
Fedi Bbm
Fedi Bbm - avatar
3 Answers
+ 7
elif is just a shorthand. I'm pretty sure using elif is more efficient, too.
14th Jan 2017, 10:31 PM
Tamra
Tamra - avatar
+ 4
*please excuse the syntax. * 1) elif means else if: //your code example x=5; if(x>6): //do something elif(x>3): *see here it's used as else if * //do something else: //do whatever 2) while in other case else: if: means that if: statement is nested inside else: example x=5; if(x>6): //do something else: if(x>3): *see here it's used as * //do something
14th Jan 2017, 10:48 PM
Pankaj Vaghela
Pankaj Vaghela - avatar
+ 2
'elif' is an alternative to the common 'else: if' ... but it not only looks better, it is easier to read and it is still clear which choices are being considered while reading the code...so if you have multiple conditions, it's more elegant to use elif <condition>: instead of: else: if <condition>
14th Jan 2017, 10:41 PM
Mohammad Hossein Barati
Mohammad Hossein Barati - avatar