Home >Backend Development >Python Tutorial >What is the if conditional statement in python? Example parsing conditional statements
In this article, we will talk about some knowledge about conditional statements. Python conditional statements are code blocks that are executed based on the execution results (True or False) of one or more statements. The Python programming language specifies that any non-zero and non-null value is true, and 0 or null is false. Pythonif statement is used to control the execution of the program. The if statement in python has a wide range of applications. Some friends who have just come into contact with python do not understand the use of this conditional statement. Next, I will introduce it in python. Usage of li statement and basic knowledge about it.
First of all, its flow chart is as follows:
can also be understood as:
if 要判断的条件: 条件成立时,要做的事情
1. For example:
age = 30 print "------if判断开始------" if age>=18: print "我已经成年了" print "------if判断结束------"
The above running results:
——if judgment starts——
I am an adult
——if judgment ends——
2. For example:
age = 16 print "------if判断开始------" if age>=18: print "我已经成年了" print "------if判断结束------"
The above running results:
——if judgment starts——
——if judgment ends——
It can be seen from the above that the above two examples only have different values of variables, and the results But it's different; we can see the role of the if judgment statement: that is, that piece of code will be executed only when certain conditions are met, otherwise that piece of code will not be executed
In this article, we understand If you don’t understand the if conditional statement in python, you can actually try it yourself. After all, hands-on practice is the best way to verify what you have learned. Finally, I hope this article can bring some help to you who are learning python.
For more related knowledge, please visit the Python tutorial column on the php Chinese website.
The above is the detailed content of What is the if conditional statement in python? Example parsing conditional statements. For more information, please follow other related articles on the PHP Chinese website!