Home  >  Article  >  Backend Development  >  How to write the if statement in python

How to write the if statement in python

silencement
silencementOriginal
2019-05-20 17:54:4629984browse

Today I will share with you the use of IF statements in Python

How to write the if statement in python

First we look at a flow chart of IF statement processing:

How to write the if statement in python

The operating principle of the IF statement is: given the conditions, decide what to do next? If the condition is true, execute the content of the decision condition code block, and exit if it is false.

Before we learn, let’s take a look at true and false in Python: In python, any non-zero, non-empty object is true, and everything except True and None is false.

Let’s take notes:

1. Any non-zero and non-empty object is interpreted as True

2. Numbers 0. Both empty objects and special objects None are false and interpreted as False

3. Comparison and equality tests will be applied to the data structure

4. The return value is True or False

Look at a few examples:

How to write the if statement in python

The basic composition of the if statement:

How to write the if statement in python

For example:

How to write the if statement in python

The above is the detailed content of How to write the if statement 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