gpt4 book ai didi

python - 什么是 "soft keywords"?

转载 作者:行者123 更新时间:2023-12-03 10:06:27 28 4
gpt4 key购买 nike

根据 keyword module 的文档,Python 3.9 中添加了两个新成员:

  • issoftkeyword
  • softkwlist

  • 然而,他们的文档并未透露任何有关其目的的信息。在 What's New中甚至没有提到这个变化。文章,其中通常记录了所有 API 更改。深入了解 source code最终导致这个 pull request其中提到“这本质上是一个内部工具”和“软关键字仍未使用”。那么 Python 的 soft 关键字的目的是什么?

    最佳答案

    简短:软关键字仍然可以用作变量或参数名称。
    PEP 622揭示了一些亮点(重点是我的):

    The difference between hard and soft keywords is that hard keywords are always reserved words, even in positions where they make no sense (e.g. x = class + 1), while soft keywords only get a special meaning in context.


    [...] The match and case keywords are proposed to be soft keywords, so that they are recognized as keywords at the beginning of a match statement or case block respectively, but are allowed to be used in other places as variable or argument names.

    关于python - 什么是 "soft keywords"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65800344/

    28 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com