pow(x, y[, z]) Return x to the power
y; if z is present, return x to the
power y, modulo z (computed more
efficiently than pow(x, y) % z). The
two-argument form pow(x, y) is
equivalent to using the power
operator: x**y.
The arguments must have numeric types.
With mixed operand types, the coercion
rules for binary arithmetic operators
apply. For int and long int operands,
the result has the same type as the
operands (after coercion) unless the
second argument is negative; in that
case, all arguments are converted to
float and a float result is delivered.
For example, 102 returns 100, but
10-2 returns 0.01. (This last
feature was added in Python 2.2. In
Python 2.1 and before, if both
arguments were of integer types and
the second argument was negative, an
exception was raised.) If the second
argument is negative, the third
argument must be omitted. If z is
present, x and y must be of integer
types, and y must be non-negative.
(This restriction was added in Python
2.2. In Python 2.1 and before, floating 3-argument pow() returned
platform-dependent results depending
on floating-point rounding accidents.)
内置的
pow
接受两个或三个参数。如果您执行from math import *
,那么它将被math的pow
替换,math只接受两个参数。我的建议是执行import math
,或者显式地列出在导入列表中使用的函数。类似的问题发生在open
与os.open
之间。http://docs.python.org/release/2.6.5/library/functions.html
也许你违反了大胆的部分?
如果您经常使用数学函数,而pow的三参数版本在Python2.7中很少使用,那么可以通过导入
__builtin__
并为3参数调用__builtin__
.pow来解决这个问题相关问题 更多 >
编程相关推荐