Python Learning conditional statement (if loop)

Source: Internet
Author: User

A python conditional statement determines the code block that executes by executing the result of one or more statements (true or false). You can easily understand the execution of conditional statements by:

The Python program language specifies any non-0 and non-null (NULL) values of true,0 or NULL to FALSE. In Python programming, if statements are used in the execution of control programs, in the basic form:

if Judging Condition:    Execute statement ... Else :    EXECUTE statement ...

The judgment condition of the IF statement can be expressed by > (greater than), < (less than), = = (equals), >= (greater than or equal), <= (less than or equal). When judging a condition as multiple values, you can use the following form:

Instance:

num =5     ifnum = =3: # Determines the value of num print'boss'elif Num==2: Print'User'elif Num==1: Print'worker'elif Num<0: # value is less than zero output print'Error'Else: Print'Roadman'# output when conditions are not true

Run:

Roadman        # Output results

You can also use the IF condition judgment statement on the same line, as in the following example:

#!/usr/bin/-*-coding:utf-8var  100 ifvar    " the   value of variable var is""good bye! "

Operation Result:

var the value is 100Good bye!

Python Learning conditional statement (if loop)

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.