Python 中的指数语法
Exponent syntax in Python
我习惯用多种语言写e^10
。但是,每次在我写 Python 的短时间内,我都会遇到这种类型错误:
TypeError: unsupported operand type(s) for ^: 'float' and 'int'
因为在 Python 中我们应该使用 **
。是什么让 Python 选择了那个运算符而不是 ^
,我认为 在编程中使用得更频繁,对我来说更自然。
^
已在 python 中取为 exclusive or
。所以 **
是更好的选择。
我习惯用多种语言写e^10
。但是,每次在我写 Python 的短时间内,我都会遇到这种类型错误:
TypeError: unsupported operand type(s) for ^: 'float' and 'int'
因为在 Python 中我们应该使用 **
。是什么让 Python 选择了那个运算符而不是 ^
,我认为 在编程中使用得更频繁,对我来说更自然。
^
已在 python 中取为 exclusive or
。所以 **
是更好的选择。