【发布时间】:2018-08-02 23:28:48
【问题描述】:
为什么^ 在 Python 中没有平方?我知道取幂是 **,但是 ^ 到底是什么,为什么不使用那个运算符呢?
例如2^2=0、3^2=1。
【问题讨论】:
-
(具体请查看the second answer)
-
^是按位异或运算符。你想要**求幂。 -
目的是让老 Fortran 程序员更容易过渡到 Python。
-
@BillBell 也是 C 程序员。
-
@shawnhcorey:另一个很好的理由。
标签: python bitwise-operators language-design exponentiation