首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >sage notebook中的运算符与从Python导入

sage notebook中的运算符与从Python导入
EN

Stack Overflow用户
提问于 2014-12-27 10:27:38
回答 1查看 223关注 0票数 0

运算符的行为取决于我如何运行我的sage程序。在笔记本中:

代码语言:javascript
运行
复制
2^10 
==>1024

使用sage -python filename.py运行我的程序

代码语言:javascript
运行
复制
from sage.all import *
print(2^10)
==> 8

我必须在Python中导入什么才能复制Sage笔记本的行为?

编辑:

感谢每个人的Python基础课程。DSM在评论中回答了这个问题,原来sage笔记本有一个预处理器。

EN

回答 1

Stack Overflow用户

发布于 2014-12-27 10:38:55

Exponentiation的python中,我们使用双星号**

代码语言:javascript
运行
复制
>>> print (2**10)
1024

或者您可以使用内置函数pow

代码语言:javascript
运行
复制
>>> pow(2, 10)
1024

电源

代码语言:javascript
运行
复制
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)运算的逐位运算符。

例如

代码语言:javascript
运行
复制
>>> a = [1,2,3]
>>> b = [3,4,5]
>>> a^b
>>> set(a)^set(b)
set([1, 2, 4, 5])

代码语言:javascript
运行
复制
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.

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27663850

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档