Python Process Control (conditional statements)

Source: Internet
Author: User

1,python Process Control single condition basic statement

2,python process Flow Multi-condition control statement

1,python Process Control single condition basic statement

If judgment condition:    Execute statement ... else:    EXECUTE statement ....

Judge the condition to be true, that is, execute the statement, otherwise execute the statement in the else. The variable is not NULL or not 0 or none is true.

 

Example:

#! /usr/bin/env python#-*-coding:utf-8-*-n = input (' Please input number: ') if n > 0:    print ' n is positive ' else:    print ' n is negative '

  

2,python process Flow Multi-condition control statement

If judgment condition 1:    EXECUTE statement 1......elif judgment Condition 2:    EXECUTE statement 2......elif judgment Condition 3: Execute statement    3......else:    EXECUTE statement 4 ...

  

Example:

#!/usr/bin/env pythonscore = Int (raw_input (' Please INPU score: ')) if score >=:    print ' A ' elif score >=:    print ' B ' elif score >=60:    print ' C ' elif score <60:    print ' D '

  

Python Process Control (conditional statements)

Related Article

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.