Why use elif if you can use if and get same result? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why use elif if you can use if and get same result?

11th Feb 2016, 9:08 PM
Luis Daniel Oliveira
Luis Daniel Oliveira - avatar
4 Answers
+ 3
To reduce the number of lines. when you use if and else only, multiple block of code has to be written comparing to use of if elif and else
13th Mar 2016, 8:10 AM
Ramesh Samiappan
0
it is kinda like if you like hotdogs, eat hotdogs, or if (elif) you like pizza or eat pizza or else (else) just eat burgers
8th Apr 2016, 1:02 PM
Cathal Aherne
Cathal Aherne - avatar
0
else is a spare part which is run when if is not true
13th Jun 2016, 9:05 AM
Iman Ali
Iman Ali - avatar
0
And if you use 'if' and not 'elif' program will check every 'if' statement for truth, and in 'elif' case iw will only check next only if previous was false - thus making less cpu and memory work, it's especially important while working with arrays and big data.
1st Jul 2016, 8:56 PM
Azriel Gridfen
Azriel Gridfen - avatar