1 Conditional Judgment
[email protected] python]# cat age.py
#!/usr/bin/python
#-*-Coding:utf-8-*-
Age=20
If Age >=18:
print (' your age : ', Ages)-- Two indented lines are considered to be a block of statements
Print (' adult ')
Else
print (' your age : ', ages)
Print (' teenager ')
if the grammatical structure
If < Conditional Judgment 1>:
< Execution 1>
Elif < Conditional Judgment 2>:
< Execution 2>
Elif < Conditional Judgment 3>:
< Execution 3>
Else
< Execution 4>
There is no end to the fi in the shell , which indicates the end of the if judgment.
If statement execution has a characteristic, it is judging from the top, if in a certain judgment is True, the judgment corresponding to the execution of the statement, will ignore the remaining elif and Else
If x:
Print (' True ')
just x Non- 0 value, non-empty string, nonempty List and so on, it is judged True, otherwise False.
if interactively passing in parameters in judgment
[email protected] python]# cat birth.py
#!/usr/bin/python
#-*-Coding:utf-8-*-
Birth=input (' Please input your birthdayyear: ')
Birth=int (birth)
If Birth > 2000:
Print (' you are after xx ')
Else
Print (' you are pre -xx ')
[email protected] python]# python birth.py
Please input your birthday year:2015
you are after xx
This article is from the "90SirDB" blog, be sure to keep this source http://90sirdb.blog.51cto.com/8713279/1795432
Python conditional judgment