Python conditional judgment

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.