Python If Else statement usage

Source: Internet
Author: User
Tags in python

Format of an If statement
The statement block must have the same indentation.
Statement block must be indented more than if,elif,else

# If conditions are true, EXECUTE statement block 1,# Otherwise, if condition 2 is established, EXECUTE statement block 2# Other cases EXECUTE statement block 3# Elis and else part are optional if condition 1: statement block 1ELIF Condition 2: statement block 2else: statement block 3
Second, the example

i = 10if i = = 3:print ' i is 3. ' Print "I also execute after if." "Elif i < 3:print ' I < 3 ' else:print ' other cases. ' Print ' prints end. '
III. Matters of note

1. There is no switch statement in Python, and switch can use If...elif...else to implement 2. If, elif, the else must have a colon (:), after which the code needs to add a layer of indentation

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.