Python基础之逻辑运算
逻辑运算
概念:
优先级() > 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基础之逻辑运算的更多相关文章
- Python开发【第二篇】:Python基础知识
Python基础知识 一.初识基本数据类型 类型: int(整型) 在32位机器上,整数的位数为32位,取值范围为-2**31-2**31-1,即-2147483648-2147483647 在64位 ...
- python 基础知识(一)
python 基础知识(一) 一.python发展介绍 Python的创始人为Guido van Rossum.1989年圣诞节期间,在阿姆斯特丹,Guido为了打发圣诞节的无趣,决心开发一个新的脚本 ...
- Day1 - Python基础1 介绍、基本语法、流程控制
Python之路,Day1 - Python基础1 本节内容 Python介绍 发展史 Python 2 or 3? 安装 Hello World程序 变量 用户输入 模块初识 .pyc是个什么鬼 ...
- Day1 Python基础学习
一.编程语言分类 1.简介 机器语言:站在计算机的角度,说计算机能听懂的语言,那就是直接用二进制编程,直接操作硬件 汇编语言:站在计算机的角度,简写的英文标识符取代二进制去编写程序,本质仍然是直接操作 ...
- Python笔记·第一章—— Python基础(一)
一.Python的简介 1.Python的由来与版本 1.1 python的由来 python的创始人为吉多·范罗苏姆(Guido van Rossum).1989年的圣诞节期间,吉多·范罗苏姆(中文 ...
- python基础(常用内容)
python基础(常用内容) 机器数: 一个数在计算机中的二进制表示形式就是机器数. 例如: +3用机器数表示就用<00000011>表示 -3用机器数表示就用<10000011&g ...
- python学习第四讲,python基础语法之判断语句,循环语句
目录 python学习第四讲,python基础语法之判断语句,选择语句,循环语句 一丶判断语句 if 1.if 语法 2. if else 语法 3. if 进阶 if elif else 二丶运算符 ...
- python基础day1
一.python介绍 1.1简介 Python (英国发音:/ˈpaɪθən/ 美国发音:/ˈpaɪθɑːn/), 是一种面向对象的解释型计算机程序设计语言,由荷兰人Guido van Rossum ...
- Python基础学习总结(持续更新)
https://www.cnblogs.com/jin-xin/articles/7459977.html 嗯,学完一天,白天上班,眼睛要瞎了= = DAY1 1,计算机基础. CPU:相当于人的大脑 ...
随机推荐
- Object-c基本语法
// // main.m // OCbasic1 // // Created by apple on 14-8-5. // Copyright (c) 2014年 苹果IOS软件开发者. Al ...
- 21.scrapy爬虫部署
1.启用 scrapyd 2. 在浏览器打开127.0.0.1:6800/ 3. scrapy.cfg 设置 4. 遇到问题: scrapyd-deploy 不是内部命令 编辑 两个配置文件 @ech ...
- GitHub使用指南之快速入门
出自http://blog.csdn.net/column/details/13170.html 1.Git安装 Git是一个版本控制系统,使用之前必须先下载安装,下面提供各平台的安装方式. Mac: ...
- mapPartitions
mapPartitions操作与 map类似,只不过映射的参数由RDD中的每一个元素变成了RDD中每一个分区的迭代器,如果映射过程需要频繁创建额外的对象,使用mapPartitions操作要比map操 ...
- Flex学习笔记,脚本式验证
<?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="ht ...
- python setattr
#object生成的对象不能使用setattr函数>>> o=object() >>> setattr(o,'name','ok') Traceback (most ...
- roadhog resolve alias 绝对路径 别名使用
新建 webpack.config.js 然后加入 如下代码 module.exports = (webpackConfig, env) => { // 别名配置 const data = we ...
- SpringBoot读取application.properties文件内容
application.properties存储数据的方式是key-value. application.properties内容 userManager.userFile=data/user.pro ...
- Xe7 System.Json解析数据格式
一.Demo一 解析嵌套数组 Json数据 {"code":1,"msg":"","data":{"Grade ...
- vscode-nextgenas编译配置
文档:https://github.com/BowlerHatLLC/vscode-nextgenas/wiki/asconfig.json asconfig.json { "config& ...