+ 1
Elif or else : if ?
what is the difference between elif and else: if
3 Answers
+ 7
elif is just a shorthand. I'm pretty sure using elif is more efficient, too.
+ 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
+ 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>