博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Python基础之逻辑运算符
阅读量:7049 次
发布时间:2019-06-28

本文共 593 字,大约阅读时间需要 1 分钟。

1456293-20180828094846132-1032745593.png

1.在没有()的情况下,not的优先级高于and,and的优先级高于or,即优先级关系为()>not>and>or,同一优先级从左往右计算。

例题,判断下列逻辑语句的结果:

3 > 4 or 4 < 3 and 1 == 1   1 < 2 and 3 < 4 or 1 > 22 > 1 and 3 < 4 or 4 > 5 and 2 < 11 > 2 and 3 < 4 or 4 > 5 and 2 > 1 or 9 < 81 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6not 2 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6
  1. x or y, 当x为True时,值就是x;x为False, 值就是False
    x and y, x 为True,值是y; x 为False, 值是X
    1456293-20180828094900949-1673517041.png
    例题:求出下列逻辑语句的值
8 or 40 and 30 or 4 and 3 or 7 or 9 and 6
  1. in, not in
    判断子元素是否在原字符串(字典,列表,集合)中:
    例如:
print("a" in "abc")print("a" not in "abc")

转载于:https://www.cnblogs.com/yang-wei/p/9546256.html

你可能感兴趣的文章
SqlLite的工具类SQLiteOpenHelper
查看>>
chgrp chown chmod
查看>>
nodejs中安装express
查看>>
2014软件表
查看>>
Struts2教程3:struts.xml常用配置解析
查看>>
(转帖)Implementing custom JavaFx Bindings
查看>>
mysql外键
查看>>
转发和重定向的区别
查看>>
<ecmall> ECMall的MySQL数据库调用
查看>>
SugarCRM - 如何修改默认首页
查看>>
Java日期类总结
查看>>
开关标识一个是0一个是-那个是开哪个是关
查看>>
ruby的并发和并行
查看>>
朱晶晶-六步制定好企业移动化战略
查看>>
SVPullToRefresh
查看>>
SSIndicatorLabel
查看>>
ASFBPostController
查看>>
Android实战技巧:Handler
查看>>
JqueryMobile实践点滴
查看>>
teamtalk服务端之完美一键部署脚本(ubuntu)
查看>>