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