If the arguments vs. else if vs. else?

BUT:

if statement: if statement: 

same as

 if statement: elif statment: 

and

 if statement: else statement: 

same? If not, then what's the difference?

+7
python if-statement
source share
3 answers

No, they do not match.

 if statement: if statement: 

If the first instruction is correct, its code will be executed. In addition, if the second statement is correct, its code will be executed.

 if statement: elif statment: 

The second block will be executed only if the first of them was not, and the second check is correct.

 if statement: else: 

The first instruction will be executed if it is true, and the second will be executed if the first is false.

+28
source share

The first is different

 if True: print 'high' #printed if True: print 'low' #printed 

than the second

 if True: print 'high' #printed elif True: print 'low' #not printed 

and the third is invalid syntax

See the tutorial .

+7
source share
 if statement: if statement: 

It is like individual conditions; each if checked one by one.

Same as:

 if statement: elif statment: 

It looks like: the first if condition failed, and then check the next after the condition.

and

if statement:

else:

It looks like this: check the first if condition, and then execute the else block.

+1
source share

All Articles