TheDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
/ operator in Python performs true division, dividing the left operand (dividend) by the right operand (divisor). For built-in real numeric types (int, float, bool), it evaluates to a floating-point (float) value, even if the division is mathematically exact. For other built-in types like complex, or standard library types like Decimal and Fraction, it returns a result of the corresponding type.
Type Coercion and Return Value
Unlike some C-family languages where integer division truncates the decimal, Python 3’s/ operator performs true division. For standard real numbers (int, float, bool), the operation always yields a float. If either or both operands are complex numbers, the operation yields a complex type.
Underlying Data Model
When the/ operator is evaluated, Python invokes the __truediv__(self, other) magic (dunder) method on the left operand. If the left operand’s class does not implement this method or returns NotImplemented, Python falls back to the __rtruediv__(self, other) method on the right operand.
Exception Handling
If the right operand evaluates to zero (e.g.,0, 0.0, 0j, False), the operation cannot be resolved mathematically, and the interpreter raises a ZeroDivisionError.
Standard Library Types
When used with standard library numeric types likedecimal.Decimal or fractions.Fraction, the / operator returns an instance of that specific type rather than a float. This behavior is defined by the __truediv__ implementation of those specific classes to preserve precision rules.
Master Python with Deep Grasping Methodology!Learn More





