The difference between the python--"/" operator and the "//" operator

Source: Internet
Author: User

First look at the use of single oblique bar: To give a few examples

>>> print (5/3), type (5/3)
1.6666666666666667
(None, <class ' float ' >)

>>> print (6/3), type (6/3)
2.0
(None, <class ' float ' >)

>>> print 5.0/3,type (5.0/3)
1.66666666667 <type ' float ' >
>>> print 5/3.0,type (5/3.0)
1.66666666667 <type ' float ' >
>>> print 5.0/3.0,type (5.0/3.0)
1.66666666667 <type ' float ' >

As can be seen, whether the value is divisible, or A/b is not an int type, single slash action is all float type, the result is to retain a number of decimal places, is our normal thinking of the division operation

Look at the example of the double oblique lever:

>>> print 5//3,type (5//3)
1 <type ' int ' >
>>> print 5.0//3,type (5.0//3)
1.0 <type ' float ' >
>>> print 5//3.0,type (5//3.0)
1.0 <type ' float ' >
>>> print 5.0//3.0,type (5.0//3.0)
1.0 <type ' float ' >
>>>

As can be seen, the return type of a//b depends on the data type of a and B, only the result is int when both A and B are int (this means that two number is being removed)

is the smallest integer of the result, and/get is the actual division result, which is the main difference between the two

The difference between the python--"/" operator and the "//" operator

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.