What to do if there are multiple conditions in Python

angryTom
Release: 2020-02-25 17:30:18
Original
34835 people have browsed it

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:  执行语句……
Copy after login

The judgment condition of the if statement You can use > (greater than), < (less than), == (equal to), >= (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……
Copy after login

Example

1. Use and for multi-condition judgment:

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

2. Use or for multi-condition judgment:

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

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;)
Copy after login

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!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!