Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

python
communitycreator

# What is math.fmod() in python?

Eman Kashif

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.   Python is a high level programming language that has a range of built-in modules and functions. The math module provides methods to perform mathematical operations in a straightforward manner. One operation is finding the modulo of two numbers, which is performed by math.fmod(). A modulo is the remainder left when a number is divided by another number.

### Syntax

math.fmod(x, y)

### Arguments

1. x: A number (positive or negative) to divide. This parameter is required.
2. y: A number (positive or negative) to divide by x. This parameter is required.

### Return Value

This function returns a float value that represents the remainder of x and y. A ValueError is returned if both x and y are zero. The same error is returned when y is zero, but not when x is zero. A TypeError is returned if x or y are not numbers.

### Code Example

#import library
import math

#display remainders of x and y
print('10 % 4:',math.fmod(10, 4))
print('200 % 5:',math.fmod(200, 5))
print('-17 % 3:',math.fmod(-17, 3))
print('15 % -4:',math.fmod(15, -4))
print('0 % 7:',math.fmod(0, 7))
print('0 % -5:',math.fmod(0, -5))
print('34 % -7:',math.fmod(34, -7))
print('18 % 4:',math.fmod(18, 4))

RELATED TAGS

python
communitycreator

CONTRIBUTOR

Eman Kashif

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.   Keep Exploring

Learn in-demand tech skills in half the time 