The difference between / and // in Python

Guanhui
Release: 2020-06-02 14:39:58
Original
76571 people have browsed it

The difference between / and // in Python

The difference between / and // in Python

In Python, "/" represents floating point division and returns a floating point result, that is The result is a floating point number, and "//" means integer division in Python, returning the largest integer that is not greater than the result, which means that the division result is rounded down.

Code

print("6 // 4 = " + str(6 // 4))
print("6 / 4 =" + str(6 / 4))
Copy after login

Result

6 // 4 = 1
6 / 4 =1.5
Copy after login

Python arithmetic operators

OperatorDescriptionInstance
Add-Add two objectsa b Output result 30
-Subtract-Get a negative number or subtract one number from another Number a - b Output result -10
*Multiply - Multiply two numbers or return a character that is repeated several times String a * b Output result 200
/division - x divided by yb / a Output result 2
%Modulo - Returns the remainder of division b % a Output result 0
**Power - Returns the y power of xa**b is 10 raised to the 20th power, and the output result is 100000000000000000000
// Take integer division - Return the integer part of the quotient (Round down)
>>> 9//24>>> -9//2-5
Copy after login

Recommended tutorial : "Python Tutorial"

The above is the detailed content of The difference between / and // in Python. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!