The/and/arithmetic operators in Python

Source: Internet
Author: User
Tags arithmetic operators integer division

Typically, the "/" arithmetic operator is calculated based on the data on either side of the participating operation, such as:

6/3 = 2; 6,3 are integers, then the result is an integer 2;

6.0/3.0 = 2.0; 6.0,3.0 is a floating-point number, then the result is also floating point 2.0, with the exact point, as long as "/" on both sides of a count is a floating point, then the result is a floating point.

This was also stated before in the Python2.2 version, but Python's designers did not consider this to be a straightforward feature of Python, and thus added an arithmetic operator "//" to represent integer division in Python2.2 and later versions. Returns a maximum integer that is not greater than the result, while "/" is purely a representation of floating-point division, but, in order to compromise, all 2. x version, also for backwards compatibility, if you want to use "//", you must add a statement:

From __future__ Import Division

When you see this, "/" means floating-point division, which returns floating-point results; "//" represents integer division.

However, when the Python3.0 is released, there is no such compromise, "/" must indicate floating-point division, return floating-point results; "//" denotes integer division.


The/and/arithmetic operators in Python

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.