5-python Learning--Conditional statements

Source: Internet
Author: User

5-python Learning--Conditional statements
    • 5-python Learning--Conditional statements
      • Conditional statement if Else form
      • If else conditional statement description
        • Test it.

Programming languages are usually made up of so many parts.

    1. Variable
    2. Conditional branching statements
    3. Looping statements
    4. Function

Here is the conditional branching statement.

Python's conditional statements and shell scripts are very similar, that is if else if else , in this form, which else if can be abbreviated as elif .

Conditional statement if Else form
if <条件判断1>:    <执行1>elif <条件判断2>:    <执行2>elif <条件判断3>:    <执行3>else:    <执行4>
If else conditional statement description

ifThe following is the judging condition, for the condition, can be made similar to the C language implicit conversion to true or false . Non-0 value, non-empty string, non-empty list, etc., judged as True , otherwise False .

Test it.
#! /usr/bin/python3.4 if 100:    print("100 --> true")true = ""if true:    print("true")else:    print("true在这里是一个空的值")    true = 100if true:    print(true)
[email protected]:~$ python3 test.py 100 --> truetrue在这里是一个空的值100

5-python Learning--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.