运算符的行为取决于我如何运行我的sage程序。在笔记本中:
2^10
==>1024使用sage -python filename.py运行我的程序
from sage.all import *
print(2^10)
==> 8我必须在Python中导入什么才能复制Sage笔记本的行为?
编辑:
感谢每个人的Python基础课程。DSM在评论中回答了这个问题,原来sage笔记本有一个预处理器。
发布于 2014-12-27 10:38:55
在Exponentiation的python中,我们使用双星号**
>>> print (2**10)
1024或者您可以使用内置函数pow。
>>> pow(2, 10)
1024电源
pow(...)
pow(x, y[, z]) -> number
With two arguments, equivalent to x**y. With three arguments,
equivalent to (x**y) % z, but may be more efficient (e.g. for longs).
enter code here^是用于执行异或(bitwise exclusive or)运算的逐位运算符。
例如
>>> a = [1,2,3]
>>> b = [3,4,5]
>>> a^b
>>> set(a)^set(b)
set([1, 2, 4, 5])Does a "bitwise exclusive or".
Each bit of the output is the same as the corresponding bit in x if that bit in y is 0,
and it's the complement of the bit in x if that bit in y is 1.
Just remember about that infinite series of 1 bits in a negative number, and these
should all make sense.https://stackoverflow.com/questions/27663850
复制相似问题