为什么Python中没有Switch⼀Case语句

2025-04-08 14:04:34
推荐回答(2个)
回答1:

Why isn’t there a switch or case statement in Python?¶
You can do this easily enough with a sequence of if... elif... elif... else. There have been some proposals for switch statement syntax, but there is no consensus (yet) on whether and how to do range tests. See PEP 275 for complete details and the current status.

For cases where you need to choose from a very large number of possibilities, you can create a dictionary mapping case values to functions to call. For example:

回答2:

因为py就是没有啊