5-python Learning--Conditional statements
- 5-python Learning--Conditional statements
- Conditional statement if Else form
- If else conditional statement description
Programming languages are usually made up of so many parts.
- Variable
- Conditional branching statements
- Looping statements
- Function
Here is the conditional branching statement.
Python's conditional statements and shell
scripts are very similar, that is if
else if
else
, in this form, which else if
can be abbreviated as elif
.
Conditional statement if Else form
if <条件判断1>: <执行1>elif <条件判断2>: <执行2>elif <条件判断3>: <执行3>else: <执行4>
If else conditional statement description
if
The following is the judging condition, for the condition, can be made similar to the C language implicit conversion to true
or false
. Non-0 value, non-empty string, non-empty list, etc., judged as True
, otherwise False
.
Test it.
#! /usr/bin/python3.4 if 100: print("100 --> true")true = ""if true: print("true")else: print("true在这里是一个空的值") true = 100if true: print(true)
[email protected]:~$ python3 test.py 100 --> truetrue在这里是一个空的值100
5-python Learning--Conditional statements