程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python 3 Learning Notes - - Conditional Control usage collation

編輯:Python

if

if_stmt ::= "if" assignment_expression ":" suite
("elif" assignment_expression ":" suite)*
["else" ":" suite]

Utilisation:

if EXPRESSION1:
SUITE1
elif EXPRESSION2:
SUITE2
else:
SUITE

Opérateur commun:

  • “<”:Moins de
  • “<=”:Jusqu'à
  • “>”:Plus grand que
  • “>=”:Supérieur ou égal à
  • “==”:égal à
  • “!=”:Pas égal à
  • “and”:Et
  • “or”:Ou

with

with_stmt ::= "with" ( "(" with_stmt_contents ","? ")" | with_stmt_contents ) ":" suite
with_stmt_contents ::= with_item ("," with_item)*
with_item ::= expression ["as" target]

Utilisation:

with EXPRESSION as TARGET:
SUITE
Ou
with A() as a, B() as b:
SUITE
Ou
with A() as a:
with B() as b:
SUITE
Ou
with (
A() as a,
B() as b,
):
SUITE

match(3.10Nouvelles caractéristiques)

match_stmt ::= 'match' subject_expr ":" NEWLINE INDENT case_block+ DEDENT
subject_expr ::= star_named_expression "," star_named_expressions?
| named_expression
case_block ::= 'case' patterns [guard] ":" block

Utilisation:

match variable: #Ici.variableC'est ce qu'il faut juger
case ["quit"]:
statement_block_1 # Code d'exécution du cas correspondant,Quandvariable="quit"Exécution àstatement_block_1
case ["go", direction]:
statement_block_2
case ["drop", *objects]:
statement_block_3
... # AutrescaseDéclarations
case _: #Et sicaseInstruction manquée,Exécuter ce bloc de code,Similaire àSwitchDedefault
statement_block_default

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved