水中有明月 发表于 2023-8-22 13:25:53

python中pow(x,y)和x**y有什么区别

是一样的吗?

liuhongrun2022 发表于 2023-8-22 13:58:56

一样

风眠 发表于 2023-8-27 10:09:49

效果一样

风眠 发表于 2023-8-27 10:16:38

区别呢,嗯,pow(x,y)是BIF,你把他覆盖了就用不了,但x**y没影响
def pow(x,y):
    return y**x
pow(x,y)
x**y
不过,我们没事也不会去覆盖它,所以你可以当他们没区别

风眠 发表于 2023-8-27 10:19:55

那个,抱歉,我说的的准确。我去看了一下,python这么解释的:
Help on built-in function pow in module builtins:

pow(x, y, z=None, /)
    Equivalent to x**y (with two arguments) or x**y % z (with three arguments)
   
    Some types, such as ints, are able to use a more efficient algorithm when
    invoked using the three argument form.
pow()有三个参数
pow(2,8,7)
2**8%7
这两个是等价的
即 pow(x,y,z) == x**y%z
页: [1]
查看完整版本: python中pow(x,y)和x**y有什么区别