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))
Result
6 // 4 = 1 6 / 4 =1.5
Python arithmetic operators
Operator | Description | Instance |
---|---|---|
Add-Add two objects | a 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 y | b / a Output result 2 |
% | Modulo - Returns the remainder of division | b % a Output result 0 |
** | Power - Returns the y power of x | a**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
Previous article:__init__ usage in Python
Next article:What are the keywords for importing other function libraries in python?
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
Latest Articles by Author
Latest Issues
Related Topics
More>
|