Consider the below statements in Python.
The first output is fine, but the second one may be surprised if we are coming Java/C++ world. In Python, the “/” operator works as a floor division for integer and float arguments. However, the operator / returns a float value if one of the arguments is a float (this is similar to C++)
The real floor division operator is “//”. It returns floor value for both integer and floating point arguments.
2 -3 2.0 -3.0
See this for example.
This article is contributed by Arpit Agrawal. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
- Benefits of Double Division Operator over Single Division Operator in Python
- Check the equality of integer division and math.floor() of Regular division in Python
- Tuple Division in Python
- Python - Dictionary Values Division
- Python | K Division Grouping
- Program to compute division upto n decimal places
- Division without using '/' operator
- Minimum steps to convert X to Y by repeated division and multiplication
- Check if N leaves only distinct remainders on division by all values up to K
- How to get element-wise true division of an array using Numpy?
- Increment and Decrement Operators in Python
- Inplace Operators in Python | Set 1 (iadd(), isub(), iconcat()...)
- Inplace Operators in Python | Set 2 (ixor(), iand(), ipow(),…)
- Inplace vs Standard Operators in Python
- Chaining comparison operators in Python
- Python Membership and Identity Operators | in, not in, is, is not
- Python Operators
- Python | Solve given list containing numbers and arithmetic operators
- Python | Splitting operators in String
- Python Logical Operators with Examples