逻辑运算

概念:

优先级() > not > and > or
print(2 > 1 and 1 < 4 or 2 < 3 and 9 > 6 or 2 < 4 and 3 < 2)
# T or T or F
# T or F
# or 一真则真
print(3 > 4 or 4 < 3 and 1 == 1)
# F or F
print(1 < 2 and 3 < 4 or 1 > 2)
# T or F
print(1 > 2 and 3 < 4 or 4 > 5 and 2 > 1 or 9 < 8)
# F or F or F
print(1 > 2 and 3 < 4 or 4 > 5 and 2 > 1 or 9 > 8 or 7 < 6)
# F or F or T or F
print(not 2 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6)
# F or F and T or F
# F and T
# int ----> bool
# 非零转换为bool True
print(bool(-2)) # True
# 0 转换成 bool 是False
print(bool(0)) # False
# bool ----> int
print(int(True)) # 1
print(int(False)) # 0
# x or y, x为真,则返回x
print(1 or 2) # 1
print(3 or 2) # 3
print(0 or 2) # 2
print(0 or 100) # 100
print(2 or 100 or 3 or 4) # 2
# 拆解
1. print(0 or 4 and 3 or 2) # 3
2. print(0 or 3 or 2)
# and 和 or返回的是相反的
print(1 and 2) # 2
print(0 and 2) # 0
# 拆解
1. print(1 > 2 and 3 or 4 and 3 < 2) # False
2. print(False or False)
# 拆解
1. print(2 or 1 < 3 and 2) # 2
2. print(2 or 2)
# 拆解
1. print(3 > 1 or 2 and 2) # True
2. print(3 > 1 or 2)

如果上面这些你是ok的,那么逻辑运算就过关了

Python基础之逻辑运算的更多相关文章

  1. Python开发【第二篇】:Python基础知识

    Python基础知识 一.初识基本数据类型 类型: int(整型) 在32位机器上,整数的位数为32位,取值范围为-2**31-2**31-1,即-2147483648-2147483647 在64位 ...

  2. python 基础知识(一)

    python 基础知识(一) 一.python发展介绍 Python的创始人为Guido van Rossum.1989年圣诞节期间,在阿姆斯特丹,Guido为了打发圣诞节的无趣,决心开发一个新的脚本 ...

  3. Day1 - Python基础1 介绍、基本语法、流程控制

    Python之路,Day1 - Python基础1   本节内容 Python介绍 发展史 Python 2 or 3? 安装 Hello World程序 变量 用户输入 模块初识 .pyc是个什么鬼 ...

  4. Day1 Python基础学习

    一.编程语言分类 1.简介 机器语言:站在计算机的角度,说计算机能听懂的语言,那就是直接用二进制编程,直接操作硬件 汇编语言:站在计算机的角度,简写的英文标识符取代二进制去编写程序,本质仍然是直接操作 ...

  5. Python笔记·第一章—— Python基础(一)

    一.Python的简介 1.Python的由来与版本 1.1 python的由来 python的创始人为吉多·范罗苏姆(Guido van Rossum).1989年的圣诞节期间,吉多·范罗苏姆(中文 ...

  6. python基础(常用内容)

    python基础(常用内容) 机器数: 一个数在计算机中的二进制表示形式就是机器数. 例如: +3用机器数表示就用<00000011>表示 -3用机器数表示就用<10000011&g ...

  7. python学习第四讲,python基础语法之判断语句,循环语句

    目录 python学习第四讲,python基础语法之判断语句,选择语句,循环语句 一丶判断语句 if 1.if 语法 2. if else 语法 3. if 进阶 if elif else 二丶运算符 ...

  8. python基础day1

    一.python介绍 1.1简介 Python  (英国发音:/ˈpaɪθən/ 美国发音:/ˈpaɪθɑːn/), 是一种面向对象的解释型计算机程序设计语言,由荷兰人Guido van Rossum ...

  9. Python基础学习总结(持续更新)

    https://www.cnblogs.com/jin-xin/articles/7459977.html 嗯,学完一天,白天上班,眼睛要瞎了= = DAY1 1,计算机基础. CPU:相当于人的大脑 ...

随机推荐

  1. Java-1.6-并发包-集合

    List相关 对于List并发包就只扩展了一个CopyOnWriteArrayList<E> Set相关 对于Set,并发包扩展ConcurrentSkipListSet<E> ...

  2. MySQL把文件导入表中

    1. Mysql 把本地文件导入表中 drop table if exists wufangzhai_caigou_group; create table wufangzhai_caigou_grou ...

  3. os sys 模块

    os.getcwd() 获取当前工作目录,即当前python脚本工作的目录路径 os.chdir("dirname") 改变当前脚本工作目录:相当于shell下cd os.chdi ...

  4. feedparser的安装

    Python中常常要利用RSS下载文本.由于这个Python开源软件嘛,碎片化特别严重.反正是各种边边角角的小问题.网上找来找去找半天都没解决如何安装.我的是win7的.python 是3.4版本的. ...

  5. [ilink32 Error] Fatal: Unable to open file 'DATA.DBXMSSQLMETADATAREADER.OBJ'

    [ilink32 Error] Fatal: Unable to open file 'DATA.DBXMSSQLMETADATAREADER.OBJ' 清除重新编译OK

  6. intellijIDEA Spring配置文件提示: File is included in 4 contexts

    前提: 不影响编码,但是出现淡黄色的背景 解决办法: 打开Project Structure —> 选择Modules -> 选择Spring ->先点减号把之前的都删除掉 -> ...

  7. LeetCode OJ 47. Permutations II

    题目 Given a collection of numbers that might contain duplicates, return all possible unique permutati ...

  8. [Linux]实际操作中命令 su 与 sudo 的区别

    ------------------------------------------------------------------------------------------------ 首先我 ...

  9. 用Delphi改变图片的像素,即大小

    我给你讲一种非常简单的方法: 第一步:在窗体上放上image1和image2两个图片控件.再放一个Button按钮控件. 第二步:在image1的Picture属性中载入一张JPG或者BMP图片.而i ...

  10. python pip 下载慢 配置使用国内源配置

    ubuntu apt 使用国内源 设置>软件和更新>下载自 选择mirrors.aliyun.com/ubuntu 更新源sudo apt-get update 安装系统包:sudo ap ...