Base de conhecimentoCentro de Exames
PT · PTPortuguês (Portugal)
Escolher idioma13

CKTIS / Python

math.sqrt

Calcula a raiz quadrada real não negativa como float.

Versão: Python 3.14; repository image, production runtime not attested

Sintaxe

math.sqrt(x, /)

Calcula a raiz quadrada real não negativa como float.

Como 9² = 81, o resultado é 9,0. A raiz de zero é 0,0.

Um argumento negativo gera ValueError e cmath.sqrt calcula raízes complexas.

import math
assert math.sqrt(81) == 9.0 and type(math.sqrt(0)) is float
assert math.sqrt(0) == 0.0

Exemplos

import math
print(math.sqrt(81))
print(math.sqrt(0))

Resultado

9.0
0.0

Um argumento negativo gera ValueError e cmath.sqrt calcula raízes complexas.

Fontes