Python和Power数学 [英] Python and Powers Math

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

问题描述

我一直在学习Python,但我有些困惑.在线讲师告诉我,当我尝试提高到一定数量时,请使用运算符**而不是^.示例:

I've been learning Python but I'm a little confused. Online instructors tell me to use the operator ** as opposed to ^ when I'm trying to raise to a certain number. Example:

print 8^3

给出11的输出,但是我所寻找的(告诉我)更类似于:print 8 ** 3给出了512的正确答案.但是为什么?

Gives an output of 11. But what I'm look for (I'm told) is more akin to: print 8**3 which gives the correct answer of 512. But why?

有人可以向我解释吗?为什么8 ^ 3不等于512,因为它是正确的答案?在什么情况下为11(8 ^ 3的结果)?

Can someone explain this to me? Why is it that 8^3 does not equal 512 as it is the correct answer? In what instance would 11 (the result of 8^3)?

我确实尝试搜索SO,但是我只看到有关除法时获得模数的信息.

I did try to search SO but I'm only seeing information concerning getting a modulus when dividing.

推荐答案

运算符^按位运算符,它执行按位异或"或"".
更多: http://wiki.python.org/moin/BitwiseOperators

Operator ^ is a bitwise operator, which does "bitwise exclusive or".
More: http://wiki.python.org/moin/BitwiseOperators

幂运算符为**,例如 8**3 ,它等于512.
参考: http://docs.python.org/reference/expressions.html #the-power-operator

The power operator is **, like 8**3 which equals to 512.
Ref: http://docs.python.org/reference/expressions.html#the-power-operator

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

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