鱼C论坛

 找回密码
 立即注册
查看: 1592|回复: 3

课后作业题未知求解

[复制链接]
发表于 2018-1-8 21:17:44 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 xiaobaicai007 于 2018-1-8 21:19 编辑

为啥等于4,而不是其他数字,小甲鱼的解释还是没看懂 0 or 0 or 4 or 6 or 9 == 4?吗  
QQ截图20180108211308.png
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2018-1-8 21:34:08 | 显示全部楼层
本帖最后由 kim-threefat 于 2018-1-8 21:36 编辑

emmmm,正好同为萌新我来回忆下。
0 or 0 or 4 or 6 or 9
0 or 0得0,0 or 4得4,4  or 6得6,6 or 9得9
PS:and 左右同为真才真,左右都真取右
       or   左右有真即为真,左右都真取左
       not 取反
0为False,其他为True

评分

参与人数 1鱼币 +1 收起 理由
qq3236398112 + 1 感谢楼主无私奉献!

查看全部评分

小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

发表于 2018-1-8 22:11:18 | 显示全部楼层
本帖最后由 冰封雪舞 于 2018-1-8 22:12 编辑

i = [0,1,2,3,4,5,6,7,8,9]
for e in i:
        for c in i:
                print('%d and %d='%(e,c),e and c,'%d or %d='%(e,c),e or c)
随便编了一段小程序看下0到9的数在and跟or的关系,懒得用range函数,见笑。
0 and 0= 0 0 or 0= 0
0 and 1= 0 0 or 1= 1
0 and 2= 0 0 or 2= 2
0 and 3= 0 0 or 3= 3
0 and 4= 0 0 or 4= 4
0 and 5= 0 0 or 5= 5
0 and 6= 0 0 or 6= 6
0 and 7= 0 0 or 7= 7
0 and 8= 0 0 or 8= 8
0 and 9= 0 0 or 9= 9
1 and 0= 0 1 or 0= 1
1 and 1= 1 1 or 1= 1
1 and 2= 2 1 or 2= 1
1 and 3= 3 1 or 3= 1
1 and 4= 4 1 or 4= 1
1 and 5= 5 1 or 5= 1
1 and 6= 6 1 or 6= 1
1 and 7= 7 1 or 7= 1
1 and 8= 8 1 or 8= 1
1 and 9= 9 1 or 9= 1
2 and 0= 0 2 or 0= 2
2 and 1= 1 2 or 1= 2
2 and 2= 2 2 or 2= 2
2 and 3= 3 2 or 3= 2
2 and 4= 4 2 or 4= 2
2 and 5= 5 2 or 5= 2
2 and 6= 6 2 or 6= 2
2 and 7= 7 2 or 7= 2
2 and 8= 8 2 or 8= 2
2 and 9= 9 2 or 9= 2
3 and 0= 0 3 or 0= 3
3 and 1= 1 3 or 1= 3
3 and 2= 2 3 or 2= 3
3 and 3= 3 3 or 3= 3
3 and 4= 4 3 or 4= 3
3 and 5= 5 3 or 5= 3
3 and 6= 6 3 or 6= 3
3 and 7= 7 3 or 7= 3
3 and 8= 8 3 or 8= 3
3 and 9= 9 3 or 9= 3
4 and 0= 0 4 or 0= 4
4 and 1= 1 4 or 1= 4
4 and 2= 2 4 or 2= 4
4 and 3= 3 4 or 3= 4
4 and 4= 4 4 or 4= 4
4 and 5= 5 4 or 5= 4
4 and 6= 6 4 or 6= 4
4 and 7= 7 4 or 7= 4
4 and 8= 8 4 or 8= 4
4 and 9= 9 4 or 9= 4
5 and 0= 0 5 or 0= 5
5 and 1= 1 5 or 1= 5
5 and 2= 2 5 or 2= 5
5 and 3= 3 5 or 3= 5
5 and 4= 4 5 or 4= 5
5 and 5= 5 5 or 5= 5
5 and 6= 6 5 or 6= 5
5 and 7= 7 5 or 7= 5
5 and 8= 8 5 or 8= 5
5 and 9= 9 5 or 9= 5
6 and 0= 0 6 or 0= 6
6 and 1= 1 6 or 1= 6
6 and 2= 2 6 or 2= 6
6 and 3= 3 6 or 3= 6
6 and 4= 4 6 or 4= 6
6 and 5= 5 6 or 5= 6
6 and 6= 6 6 or 6= 6
6 and 7= 7 6 or 7= 6
6 and 8= 8 6 or 8= 6
6 and 9= 9 6 or 9= 6
7 and 0= 0 7 or 0= 7
7 and 1= 1 7 or 1= 7
7 and 2= 2 7 or 2= 7
7 and 3= 3 7 or 3= 7
7 and 4= 4 7 or 4= 7
7 and 5= 5 7 or 5= 7
7 and 6= 6 7 or 6= 7
7 and 7= 7 7 or 7= 7
7 and 8= 8 7 or 8= 7
7 and 9= 9 7 or 9= 7
8 and 0= 0 8 or 0= 8
8 and 1= 1 8 or 1= 8
8 and 2= 2 8 or 2= 8
8 and 3= 3 8 or 3= 8
8 and 4= 4 8 or 4= 8
8 and 5= 5 8 or 5= 8
8 and 6= 6 8 or 6= 8
8 and 7= 7 8 or 7= 8
8 and 8= 8 8 or 8= 8
8 and 9= 9 8 or 9= 8
9 and 0= 0 9 or 0= 9
9 and 1= 1 9 or 1= 9
9 and 2= 2 9 or 2= 9
9 and 3= 3 9 or 3= 9
9 and 4= 4 9 or 4= 9
9 and 5= 5 9 or 5= 9
9 and 6= 6 9 or 6= 9
9 and 7= 7 9 or 7= 9
9 and 8= 8 9 or 8= 9
9 and 9= 9 9 or 9= 9
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-1-8 23:20:55 | 显示全部楼层
在Python看来,只有以下内容会被看作假(注意冒号里面啥都没有,空格都不要有!):
        False None 0 '' "" () [] {}
所以0等同于假,假等同于0
0 or 其他非零数的时候为后面的那个数
两个非零数中间放个 or 遵循短路逻辑,答案为o r 前面的那个数
0and任何其它数都为0
两个非零数中间放个 and 遵循短路逻辑,答案为 and 后面的那个数
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-12-27 01:20

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表