Why doesn't Python have switch-case?

前端 未结 4 1304
遇见更好的自我
遇见更好的自我 2021-01-30 08:17

Please explain why Python does not have the switch-case feature implemented in it.

4条回答
  •  臣服心动
    2021-01-30 08:55

    There is literally a section in the docs to answer this. See below:

    Why isn’t there a switch or case statement in Python?

    TL;DR: existing alternatives (dynamic dispatch via getattr or dict.get, if/elif chains) cover all the use cases just fine.

提交回复
热议问题