Python __future__ and floor division (//)

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/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Yongqiang Cheng

梦想不是浮躁,而是沉淀和积累。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值