在这篇文章里,我们会聊一聊为什么 Python 决定不支持 switch 语句。 为什么想要聊这个话题呢? 主要是因为 switch 在其它语言中太常见了,而 Python 却不支持,这样的独特性本身就值得关注,而回答这个问题,也能更加看清 Python 在程序设计上的理念,了解 Python 在语法设计中的决策过程。 本文除了会详细分析 PEP-275 ...
主要是因为 switch 在其它语言中太常见了,而python 却不支持,这样的独特性本身就值得关注,而回答这个问题,也能更加看清python 在程序设计上的理念,了解python 在语法设计中的决策过程。 本文除了会详细分析 PEP-275 和 PEP-3103,还会介绍到 Python 最新的发展动态(PEP-622),即可能要引入的模式匹配(pattern matching...
主要是因为 switch 在其它语言中太常见了,而 Python 却不支持,这样的独特性本身就值得关注,而回答这个问题,也能更加看清 Python 在程序设计上的理念,了解 Python 在语法设计中的决策过程。本文除了会详细分析 PEP-275 和 PEP-3103,还会介绍到 Python 最新的发展动态(PEP-622),即可能要引入的模式匹配(patte...
在基础语法之外,Guido 花了很多篇幅来讨论扩展语法(Extended Syntax),即在一个 case 分支中实现匹配多个值的复杂情况: 他重点考虑到的问题包括:switch 中表达式的结果是元组或可迭代对象的情况、case 的值被看成元组解包的情况、在 case 分支作“*”星号操作…… 接着,Guido 又用了非常非常多的篇幅来分析该如何...
来源:Python猫 在这篇文章里,我们会聊一聊为什么 Python 决定不支持 switch 语句。 为什么想要聊这个话题呢? 主要是因为 switch 在其它语言中太常见了,而python 却不支持,这样的独特性本身就值得关注,而回答这个问题,也能更加看清python 在程序设计上的理念,了解python 在语法设计中的决策过程。
但是,在 Python 中,我们看不到 switch-case 或者相近的语法结构,这是为什么呢? 2、Python 为什么不支持 switch? 官方文档中有一篇 FAQ 包含了这个问题:Why isn’t there a switch or case statement in Python? FAQ 即 Frequently Asked Questions 的缩写,表示常见问题,官方列了 27 个常见问题,完整清单在此:...
主要是因为 switch 在其它语言中太常见了,而 Python 却不支持,这样的独特性本身就值得关注,而回答这个问题,也能更加看清 Python 在程序设计上的理念,了解 Python 在语法设计中的决策过程。 本文除了会详细分析 PEP-275 和 PEP-3103,还会介绍到 Python 最新的发展动态(PEP-622),即可能要引入的模式匹配(pattern mat...
The general syntax for switch case in Python is as in this example, the dictionary “switch_case” is used to map conditions to corresponding codes. Thus, if the variable “variable” is not present in the dictionary, the function “functioning” will execute the code for the “default” ca...
MagicPython doesn't seem to have been updated in 2 years, meaning it doesn't support any of the new syntax in python 3.12: MagicStack/MagicPython#262 MagicStack/MagicPython#265 it seems very odd that these new features came out 6 months ...
# Empty suites are considered syntax errors, so intentional fall-throughs # should contain 'pass' c = 'z' for case in switch(c): if case('a'): pass # only necessary if the rest of the suite is empty if case('b'): pass