Python 3.10来了,switch语法终于出现
程序IT圈
共 2939字,需浏览 6分钟
· 2021-04-23
转自 | 机器之心
对于从事数据科学和人工智能领域的人们来说,Python 是大家的首选编程语言。根据最近的一项调查,27% 的程序员开发职位要求掌握 Python 语言,今年年初这一数字还只是 18.5%。
with (
CtxManager1() as example1,
CtxManager2() as example2,
CtxManager3() as example3,
):
...
match subject:
case <pattern_1>:
<action_1>
case <pattern_2>:
<action_2>
case <pattern_3>:
<action_3>
case _:
<action_wildcard>
http_code = "418"
match http_code:
case "200":
print("OK")
do_something_good()
case "404":
print("Not Found")
do_something_bad()
case "418":
print("I'm a teapot")
make_coffee()
case _:
print("Code not found")
http_code = "418"
if http_code == "418":
print("OK")
do_something_good()
elif http_code == "404":
print("Not Found")
do_something_bad()
elif http_code == "418"
print("I'm a teapot")
make_coffee()
else:
print("Code not found")
感谢你的分享,点赞,在看三连
评论