Python中文
首页
教程
问答
标签
搜索
登录
注册
求值+2+4%1表达式`
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>考虑这个表达式<code>3 + 2 + 1 - 5 + 4 % 2 - 1 / 4 + 6</code>。在</p> <p><a href="https://duckduckgo.com/?q=3%20%2B%202%20%2B%201%20-%205%20%2B%204%20%25%202%20-%201%20%2F%204%20%2B%206" rel="nofollow">DuckDuckGo</a>将其计算为<code>6.75</code>(Google也是如此)。在</p> <p>Python 2将其计算为7:</p> <pre><code>$ python Python 2.7.5 (default, Mar 9 2014, 22:15:05) [GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> print 3 + 2 + 1 - 5 + 4 % 2 - 1 / 4 + 6 7 >>> ^D </code></pre> <p>Python3将其计算为6.75:</p> ^{pr2}$ <p>为什么python2的计算结果是7,python3的计算结果是6.75?在</p> <p>Python是如何得到结果的?在</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>在py2中,1/4->;0表示整数;在py3中,1/4->;0.25。可以在py2中使用显式的真除法</p> <pre><code>3 + 2 + 1 - 5 + 4 % 2 - 1. / 4 + 6 # note the decimal point </code></pre> <p>或者你可以做一个</p> ^{pr2}$ <p>使用py3行为。在</p>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
将Pandas数据帧转换为PyTorch张量?
7 回答
将Pandas数据帧转换为scipy稀疏矩阵
1 回答
将Pandas数据帧转换为Spark Datafram时出现问题
4 回答
将pandas数据帧转换为spark DataFram时出错
5 回答
将Pandas数据帧转换为spark datafram时收到错误
8 回答
将Pandas数据帧转换为Spark数据帧
7 回答
将Pandas数据帧转换为Tensorflow数据
5 回答
将Pandas数据帧转换为tkinter obj
4 回答
将pandas数据帧转换为XML
9 回答
将Pandas数据帧转换为值sql语句
9 回答
将pandas数据帧转换为元组
8 回答
将pandas数据帧转换为元组列表
8 回答
将pandas数据帧转换为元组列表并删除所有pandas数据类型
1 回答
将pandas数据帧转换为具有头和数据类型的numpy数组
2 回答
将pandas数据帧转换为内存中的拼花地板,并将其加载到Python中的Hadoop中
7 回答
将pandas数据帧转换为内存中类似文件的对象?
7 回答
将Pandas数据帧转换为内存功能(&F)
3 回答
将pandas数据帧转换为列表列表
1 回答
将pandas数据帧转换为列表列表以输入到RNN
3 回答
将Pandas数据帧转换为单行DataFram
10 回答