Python数学模块 [英] Python math module

查看:140
本文介绍了Python数学模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我尝试使用Python的exponentiation和logarithms模块的任何内置函数时,都会出现如下错误:

Whenever I try to use any of the built-in functions of Python's exponentiation and logarithms module, I get an error like this:

NameError: name 'sqrt' is not defined

我尝试过使用 math.sqrt(4) sqrt(4) sqrt(4.0) ,但它们都不起作用。例外情况是 pow ,它按预期工作。这真的很奇怪,我不确定是什么问题。

I have tried using math.sqrt(4),sqrt(4) and sqrt(4.0), but none of them work. The exception is pow, which works as it's supposed to. This is really strange and I'm not sure what's wrong.

推荐答案

pow 内置于语言中(不属于数学库)。问题是你没有输入数学。

pow is built into the language(not part of the math library). The problem is that you haven't imported math.

试试这个:

import math
math.sqrt(4)

这篇关于Python数学模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆