+ 1

Does any one know the difference between elif and else? In python

I do not know that I should use elif or else after if?

11th Nov 2016, 12:07 AM
Mohammad Mohkami
Mohammad Mohkami - avatar
5 Réponses
+ 5
to choose between elif and else you have to decide if you need another condition checked before executing code. elif is essentially an else block with a new if statement inside it. elif - use if you have another condition to check else - use if you want code to execute without another condition checked
11th Nov 2016, 1:44 PM
Luke Armstrong
+ 2
The elif is used in place of "else if"........ just a quicker and short form of "else if"..... remember that an "if" expression comes before any "elif"s ....and also ends with an "else" expression...... format=> if......... elif...... elif...... elif...... else:..... u can have as many elif (s) as you want
11th Nov 2016, 12:26 AM
Alabi Oyewumi Emmanuel
Alabi Oyewumi Emmanuel - avatar
+ 2
if condition1: statement1 elif condition2: statement2 else statement3 if condition1 is true,statement1 will be executed. else,if condition2 is true,statement2 will be executed. else,statement3 will be executed.
11th Nov 2016, 10:01 AM
Dandi Wiratsangka
Dandi Wiratsangka - avatar
+ 2
"elif" is short for "else if" and is used for more possible outcomes or conditions in an "if" statement. "elif" can be used as many times as desired in a single "if" statement. For example: Here is an example of "if" statement format using "elif" if condition1: statement1 elif condition2: statement2 elif condition3: statement3 ........ else: final statement A major difference between "elif" and "else" is that the "elif" is used mid-statement of the "if" statement to introduce additional conditions while the "else" is used at the end of the "if" statement to introduce the final condition "elseif", "elsif" and "else if" can be used in place of "elif"
11th Nov 2016, 11:49 PM
Ade-onojobi Oluwadewalade
Ade-onojobi Oluwadewalade - avatar
+ 1
You can use "elif" like an "if" if you want more possibilies
11th Nov 2016, 1:04 AM
Barraqus
Barraqus - avatar