sage笔记本中的运算符与从Python导入
操作员的行为因我运行sage程序的方式而异。 在笔记本中:sage笔记本中的运算符与从Python导入,python,sage,Python,Sage,操作员的行为因我运行sage程序的方式而异。 在笔记本中: 2^10 ==>1024 使用sage-python filename.py运行我的程序: from sage.all import * print(2^10) ==> 8 我必须在Python中导入什么才能复制Sage笔记本的行为 编辑: 感谢大家上了基本的Python课程。DSM回答了这个问题 在评论中,sage笔记本有一个预处理器。在python中,我们使用双asterik** >>> prin
2^10
==>1024
使用sage-python filename.py运行我的程序:
from sage.all import *
print(2^10)
==> 8
我必须在Python中导入什么才能复制Sage笔记本的行为
编辑:
感谢大家上了基本的Python课程。DSM回答了这个问题
在评论中,sage笔记本有一个预处理器。在python中,我们使用双asterik
**
>>> print (2**10)
1024
也可以使用内置函数pow
>>> pow(2, 10)
1024
pow
^
是用于执行XOR(按位异或
)操作的按位运算符
例如:
^
是Python中的按位异或运算符。要通电,请使用**
运算符。:打印(2**10)
,或使用pow
函数:pow(2,10)
:这不是预处理器所做的唯一细微更改。例如,在Sage中,2/3将在QQ中生成rational,但在Python中生成0。在编写要导入的代码时,重要的是要考虑Python而不是Sage。
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
>>> 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.