In recent versions of Python (3 onwards), integer division (dividing two integers) yields a float instead of an integer. This behavior differs from earlier versions, which favored integer results for integer operands.
Consider the following division in Python 3:
>>> 2 / 2 1.0
This surprising result may cause confusion, especially if you're accustomed to older Python versions.
The rationale for this change is documented in PEP-238: Changing the Division Operator. The proposal aimed to:
This change has several implications for your Python code:
Example:
# Explicit floor division result = 2 // 2 # 1 # Float division result = 2 / 2 # 1.0
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3