Judgment statement in python

Source: Internet
Author: User

Judgment statement in python
The Python programming language specifies that any non-0 and non-null (null) values are true, and 0 or null values are false. In Python programming, if statements are used to control program execution. The basic form is: if judgment condition: execution statement ...... Else: Execute the statement ...... When the "judgment condition" is set to a non-zero value, the following statement is executed, and the execution content can be multiple rows, which are indented to indicate the same range. Else is an optional statement. You can execute related statements when the conditions are not met. For example: # Example 1: Basic if usage #! /Usr/bin/python #-*-coding: UTF-8-*-flag = Falsename = 'luren' if name = 'python ': # determine whether the variable is 'python' flag = True # When the condition is set, set the flag to True print 'Welcome boss' # and output the welcome information else: print name # When the condition is not met, the output variable name output result is: >>> luren # The output result. if statement judgment conditions can be> (greater than), <(less), = (equal to), >=( greater than or equal to), and <= (less than or equal to) indicate the relationship. If the condition is multiple values, use the following form: if condition 1: Execute Statement 1 ...... Elif condition 2: Statement 2 ...... Elif Condition 3: Statement 3 ...... Else: Execute Statement 4 ...... # Example 2: elif usage num = 5 if num = 3: # determine the num value print 'boss' elif num = 2: print 'user' elif num = 1: print 'worker' elif num <0: # print 'error' else: print 'roadman 'If the value is less than zero # output when none of the conditions are met

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.