Python `__future__` and floor division [`//`]
Glossary
https://docs.python.org/3.10/glossary.html
术语对照表
https://docs.python.org/zh-cn/3.10/glossary.html
glossary ['glɒs(ə)rɪ]:n. 术语 (特殊用语) 表,词汇表,专业词典
1. __future__
A future statement, from __future__ import <feature>
, directs the compiler to compile the current module using syntax or semantics that will become standard in a future release of Python. The __future__
module documents the possible values of feature. By importing this module and evaluating its variables, you can see when a new feature was first added to the language and when it will (or did) become the default:
future 语句, from __future__ import <feature>
指示编译器使用将在未来的 Python 发布版中成为标准的语法和语义来编译当前模块。__future__
模块文档记录了可能的 feature 取值。通过导入此模块并对其变量求值,你可以看到每项新特性在何时被首次加入到该语言中以及它将 (或已) 在何时成为默认:
>>> import __future__
>>> __future__.division
_Feature((2, 2, 0, 'alpha', 2), (3, 0, 0, 'alpha', 0), 8192)
2. floor division - 向下取整除法
Mathematical division that rounds down to nearest integer. The floor division operator is //
. For example, the expression 11 // 4
evaluates to 2 in contrast to the 2.75 returned by float true division. Note that (-11) // 4
is -3 because that is -2.75 rounded downward. See PEP 238.
向下舍入到最接近的整数的数学除法。向下取整除法的运算符是 //
。例如,表达式 11 // 4
的计算结果是 2,而与之相反的是浮点数的真正除法返回 2.75。注意 (-11) // 4
会返回 -3,因为这是 -2.75 向下舍入得到的结果。见 PEP 238。
pseudo ['sjuːdəʊ]:n. 伪君子,假冒的人 adj. 冒充的,假的
Microsoft Windows [版本 6.1.7601]
版权所有 (c) 2009 Microsoft Corporation。保留所有权利。
C:\Users\foreverstrong>python
Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 08:06:12) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> 11 / 4
2.75
>>>
>>> 11 // 4
2
>>>
>>> (-11) / 4
-2.75
>>>
>>> (-11) // 4
-3
>>>
>>> exit()
C:\Users\foreverstrong>
References
[1] Yongqiang Cheng, https://yongqiang.blog.csdn.net/