gpt4 book ai didi

python - python中下划线是什么意思

转载 作者:行者123 更新时间:2023-11-30 23:30:55 24 4
gpt4 key购买 nike

大家好,从我的问题中可以明显看出,我就像一个 Python 新手。当我阅读有关 python 的文档甚至 Stackoverflow 论坛时,我感到非常困惑......

他们为什么这样写

from __future__ import division

Future 一词周围的下划线是什么意思?我们是否应该在 python 解释器中像下划线一样使用它?这只是众多例子之一。任何帮助将不胜感激。

最佳答案

根据PEP 236在提议此模块的地方,双下划线使其成为保留名称。

[5] This ensures that a future_statement run under a release prior to
the first one in which a given feature is known (but >= 2.1) will
raise a compile-time error rather than silently do a wrong thing.
If transported to a release prior to 2.1, a runtime error will be
raised because of the failure to import __future__ (no such module
existed in the standard distribution before the 2.1 release, and
the double underscores make it a reserved name).

关于python - python中下划线是什么意思,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20274340/

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