Home > Backend Development > Python Tutorial > What does python elif mean?

What does python elif mean?

silencement
Release: 2020-09-15 17:47:28
Original
131555 people have browsed it

Elif in Python means to judge again, which is the abbreviation of else if. The elif statement cannot be used independently, but can be used together with if and else when more conditions need to be checked. An if statement can contain multiple elif statements, but there can only be one else statement at the end.

What does python elif mean?

In Python, elif means to judge again, which is the abbreviation of else if.

In Python, you can use if-elif-else statements to implement multiple conditional judgments

else and elif statements can also be called clauses, and they cannot be used independently. , both appear inside if, for, and while statements. The else clause can add a choice; the elif clause is used when more conditions need to be checked, and is used together with if and else. elif is the abbreviation of else if.

How to use if, elif and else

What does python elif mean?

##Run the above code, the output result is as follows

What does python elif mean?

#When the above program is executed, the if statement is first executed. If it is true, the following elif and else statements will be ignored; if it is not true, then execute elif statement; if the elif statement still does not hold, the last else statement is executed.


When using if and else and elif statements, please pay attention to the following two points:

1. else and elif are sub-blocks and cannot be used independently

2. An if statement can contain multiple elif statements, but there can only be one else statement at the end

The role of else in while and for loop statements

In python, you can use the else clause in while and for loops. It will only be executed after the loop ends. If the break statement is used at the same time, the else clause block will be skipped. So note that the else clause and the break statement cannot be used at the same time!

The above is the detailed content of What does python elif mean?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template