Python math.fmod() Método

Python math 模块Módulo math de Python

Python math.fmod(x, y)El método devuelve el resto de x/y.

Versión de Python: 2.7

Sintaxis

La sintaxis del método math.fmod() es la siguiente:

math.fmod(x, y)

Descripción de parámetros:

  • x-- Obligatorio, positivo o negativo. Dividendo. Si x no es un número, devuelve TypeError.
  • y-- Obligatorio, positivo o negativo. Divisor. Si y no es un número, devuelve TypeError.

Nota:Si x e y = 0, se devuelve ValueError.

Nota:Si y = 0, se devuelve ValueError.

Nota:Si x o y no es un número, se devuelve TypeError.

Valor de retorno

Un valor de punto flotante que representa el resto de x/y

Ejemplo

El siguiente ejemplo calcula el resto:

Ejemplo

# Importar el paquete math
import math

# Calcular el resto
print(math.fmod(20, 4))
print(math.fmod(20, 3))
print(math.fmod(15, 6))
print(math.fmod(-10, 3))

# Error, ValueError: math domain error
print(math.fmod(0, 0))

Resultado de salida:

0.0
2.0
3.0
-1.0
Traceback (most recent call last):
    File "/Users/EJEMPLO/ejemplo-test/test.py", line 9, in <module>
    print(math.fmod(0, 0))
ValueError: math domain error

Python math 模块Módulo math de Python

Otras extensiones