Home  >  Article  >  Backend Development  >  What to do if there are multiple conditions in Python

What to do if there are multiple conditions in Python

angryTom
angryTomOriginal
2020-02-25 17:30:1834840browse

What to do if there are multiple conditions in Python

What to do if there are multiple conditions in Python

If there are multiple conditions in Python, you can use the and, or, elif keywords to connect.

The if statement in Python programming is used to control the execution of the program. The basic form is: (Recommended: python video tutorial)

if 判断条件:  执行语句……else:  执行语句……

The judgment condition of the if statement You can use > (greater than), 2342cb0436bd835a7369fdb5de0d7456= (greater than or equal to), <= (less than or equal to) to express the relationship.

When the judgment condition is multiple values, you can use the following form:

if 判断条件1:  执行语句1……elif 判断条件2:  执行语句2……elif 判断条件3:  执行语句3……else:  执行语句4……

Example

1. Use and for multi-condition judgment:

if name == &#39;zs&#39; and age == 18:
    print(&#39;name: zs, age: 18&#39;)

2. Use or for multi-condition judgment:

if passwd == &#39;123456&#39; or passwd == &#39;abcdef&#39;
    print(&#39;welcome!&#39;)

3. Use elif for multi-condition judgment:

if user == &#39;zs&#39;;
    print(&#39;hi zs&#39;)
elif user == &#39;ls&#39;:
    print(&#39;hi li&#39;)

php Chinese website, a large number of python tutorials and related Programming tutorial, welcome to learn.       

The above is the detailed content of What to do if there are multiple conditions in Python. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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