Python learning [13th] conditions and loops

Source: Internet
Author: User

Python learning [13th] condition and circular if statement single if statement

The IF statement has three parts, the keyword if itself, the conditional expression that determines whether the result is true, and whether the expression is real or not 0 is the code that executes

If expression:

Expr_true_suite

The conditional expression can be multiple by using the Boolean operator and or not to implement the

If code block for a single statement, if the execution code of the IF statement has only one line, it can be put on a line to write

If Expresssion:expr_tru_suite

if Print True ... True

Else statement

The syntax is as follows:

if expression:    expr_true_suiteElse:    expr_false_suite

Elf statements

can have multiple elif, but only by one if one else, the syntax is as follows

if expression1:    expr1_true_suiteelif  expression2:    expr2_true_suiteelif  expression3:    expr3_true_suite .... elif Expressionx:    exprx_true_suiteElse:     none_of_above_suite

There are no switch/case statements in Python

We can do this through a dictionary, note that the value after the dictionary is not quoted, the corresponding method should be defined in front of the dictionary.

defInsert_met ():Print "This is Insert_met"defDelete_met ():Print "This is Delete_met"defUpdate_met ():Print "This is Update_met"CMDs={"Insert": Insert_met,"Delete":d Elete_met,"Update": Update_met}defChoice (m): Cmds[m] () Choice ('Insert') Choice ('Update') Choice ('Delete')

Implementation of ternary operators in Python

Python learning [13th] conditions and loops

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.