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

Python3 learning notes -- collation of conditional control usage

編輯:Python

if

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

usage :

if EXPRESSION1:
SUITE1
elif EXPRESSION2:
SUITE2
else:
SUITE

Common operators :

  • “<”: Less than
  • “<=”: Less than or equal to
  • “>”: Greater than
  • “>=”: Greater than or equal to
  • “==”: be equal to
  • “!=”: It's not equal to
  • “and”: also
  • “or”: perhaps

with

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

usage :

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

match(3.10 New characteristics )

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

usage :

match variable: # there variable It's what needs to be judged 
case ["quit"]:
statement_block_1 # The execution code of the corresponding case , When variable="quit" When the statement_block_1
case ["go", direction]:
statement_block_2
case ["drop", *objects]:
statement_block_3
... # Other case sentence 
case _: # If the top case Statement misses , Then execute this code block , Be similar to Switch Of default
statement_block_default

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