❮ Math Methods
Example
Return the remainder of x with respect to y:
# Import math Library
import math
# Return the remainder of x/y
print [math.remainder[9, 2]]
print [math.remainder[9, 3]]
print [math.remainder[18, 4]]
Try it Yourself »
Definition and Usage
The math.remainder[]
method returns the remainder of x with respect to y.
Syntax
Parameter Values
x | Required. The number you want to divide. |
y | Required. The number you want to divide with. It must be a non-zero number, or a ValueError occurs. |
Technical Details
A float value, representing the remainder
|
3.7 |
More Examples
Example
Return the remainder of x/y:
print [math.remainder[23.5, 5]]
print [math.remainder[23, 5.5]]
print [math.remainder[12.5, 2.5]]
print [math.remainder[12, 2]]
Try it Yourself »
❮ Math Methods
Python Operators
Operators are used to perform operations on variables and values.
In the example below, we use the +
operator to add together two values:
Python divides the operators in the following groups:
- Arithmetic operators
- Assignment operators
- Comparison operators
- Logical operators
- Identity operators
- Membership operators
- Bitwise operators
Python Arithmetic Operators
Arithmetic operators are used with numeric values to perform common mathematical operations:
+ | Addition | x + y | Try it » |
- | Subtraction | x - y | Try it » |
* | Multiplication | x * y | Try it » |
/ | Division | x / y | Try it » |
% | Modulus | x % y | Try it » |
** | Exponentiation | x ** y | Try it » |
// | Floor division | x // y | Try it » |
Python Assignment Operators
Assignment operators are used to assign values to variables:
= | x = 5 | x = 5 | Try it » |
+= | x += 3 | x = x + 3 | Try it » |
-= | x -= 3 | x = x - 3 | Try it » |
*= | x *= 3 | x = x * 3 | Try it » |
/= | x /= 3 | x = x / 3 | Try it » |
%= | x %= 3 | x = x % 3 | Try it » |
//= | x //= 3 | x = x // 3 | Try it » |
**= | x **= 3 | x = x ** 3 | Try it » |
&= | x &= 3 | x = x & 3 | Try it » |
|= | x |= 3 | x = x | 3 | Try it » |
^= | x ^= 3 | x = x ^ 3 | Try it » |
>>= | x >>= 3 | x = x >> 3 | Try it » |
Chủ Đề |