首页 > 其他分享 >03 逻辑运算符.

03 逻辑运算符.

时间:2023-02-27 17:22:06浏览次数:33  
标签:03 逻辑 False 10 res 运算符 条件 print True

# 一:not、and、or的基本使用
# not:就是把紧跟其后的那个条件结果取反
# ps:not与紧跟其后的那个条件是一个不可分割的整体
# print(not 16 > 13)
# print(not True)
# print(not False)
# print(not 10)
# print(not 0)
# print(not None)
# print(not '')

# and:逻辑与,and用来链接左右两个条件,两个条件同时为True,最终结果才为真
# print(True and 10 > 3)

# print(True and 10 > 3 and 10 and 0) # 条件全为真,最终结果才为True
# print( 10 > 3 and 10 and 0 and 1 > 3 and 4 == 4 and 3 != 3) # 偷懒原则

# or:逻辑或,or用来链接左右两个条件,两个条件但凡有一个为True,最终结果就为True,
# 两个条件都为False的情况下,最终结果才为False
# print(3 > 2 or 0)
# print(3 > 4 or False or 3 != 2 or 3 > 2 or True) # 偷懒原则

# 二:优先级not>and>or
# ps:
# 如果单独就只是一串and链接,或者说单独就只是一串or链接,按照从左到右的顺讯依次运算即可(偷懒原则)
# 如果是混用,则需要考虑优先级了

# res=3>4 and not 4>3 or 1==3 and 'x' == 'x' or 3 >3
# print(res)
#
# # False False False
# res=(3>4 and (not 4>3)) or (1==3 and 'x' == 'x') or 3 >3
# print(res)



res=3>4 and ((not 4>3) or 1==3) and ('x' == 'x' or 3 >3)
print(res)



标签:03,逻辑,False,10,res,运算符,条件,print,True
From: https://www.cnblogs.com/wiii/p/17160513.html

相关文章

  • 2022-03-15 最新博客爬虫
    importrequestsurl="https://www.cnblogs.com/AggSite/AggSitePostList"data={"CategoryType":"SiteHome","ParentCategoryId":0,"CategoryId":808,......
  • Python 错误:ModuleNotFoundError: No module named 'conf'
    问题描述:编译器无法使用cmd命令来执行py文件,结果可能报ModuleNotFoundError的错误。比如在cmd任务栏执行:python E:\myProgram\Python\spider\NetDealer\core\ot......
  • 华为LAB实验室-2逻辑回归
    各位好,我是乾颐堂大堂子。领取完整实战指南可以私信我,关键词:“实战指南”~在逻辑回归部分,使用的数据集为自定义的房屋租金和面积相关的数据集,在实验初始阶段会进行定义。步......
  • Python变量与运算符一
    一、Python保留字符(33个)被编程语言内部定义并保留使用的标识符:and,as,assert,break,class,continue,def,del,elif,else,expect,finally,for,from,False,global,if,is,im......
  • java基础03
    变量类变量static PublicclassDemo08{staticdoublesalary=2500;//static从属于Demo08这个类 方便调用//属性:变量//实例变量从属于对象;如果不自动初始化 ,这......
  • python requests请求出现 requests.exceptions.ConnectionError: ('Connection aborte
    pythonrequests请求出现requests.exceptions.ConnectionError:('Connectionaborted.',OSError(22,'Invalidargument'))Traceback(mostrecentcalllast):File......
  • SyntaxError: Non-ASCII character '\xe8' in file test.py on line 6,
     001、python报错SyntaxError:Non-ASCIIcharacter'\xe8'infiletest.pyonline6原因:注释行中出现了中文  ,而python支持的ASCII码不支持中文。 002、解......
  • 这样在管理后台里实现 403 页面实在是太优雅了
    前言403页面通常表示无权限访问,与404页面代表着不同含义。而大部分管理后台框架仅提供了404页面的支持,但却忽略了对403页面的处理,有的框架虽然也有对403页面的处......
  • 读Java性能权威指南(第2版)笔记03_ Java SE API技巧中
    1. 缓冲I/O1.1. 对于文件和套接字,压缩和字符串编码的操作,必须适当地对I/O进行缓冲1.1.1. 两个流操作的是字节块(来自缓冲流)而不是一系列的单字节(来自ObjectOutputStre......
  • day03-面向对象高级3-内部类&枚举&泛型
    1,内部类回顾:之前学了类的四个成员,分别是成员变量,成员方法,代码块,构造器,现在这是第五个成员,内部类;前三个作了解,第四个重点学习。内部类的应用场景......