Python逻辑运算
一.运算符种类
1.比较运算符 > ,< , >= ,<= , != , ==
2.赋值运算符 =, +=,-=,*=,/=,**=,%=
3.成员运算符 in not in
4.算数运算符 + ,-,*,/,**,%
5.逻辑运算符 not and or
二.运算符运算顺序
括号>算数运算符(+,-,*,/,%,//,**)>比较操作符(>,<,!=,=)>not>and>or
三.and,or,not逻辑运算结果
1.在and关系中,两者都为真,选择后者
print(1 and 2)
print(2 and 1)
print(True and 1)
print(1 and True)
运算结果:
2
1
1
True
2.在and关系中,有一个为假,那么结果就是假
print(1 and 0)
print(0 and 1)
print(1 and False)
print(False and 1)
运算结果:
0
0
False
False
3.在and关系中,多个假,那么结果是出现的第一个假,因为发现假,那么后面的结果不会影响最终结果,所以逻辑运算结束
print(0 and False)
print(False and 0) 运算结果:
0
False
4.在or关系中,多个假,没有真,那么一定是最后一个假作为结果,因为当发现第一个假,并不代表后面没有真,所以继续逻辑运算直到最后
print(False or 0)
print(0 or False)
运算结果:
0
False
5.在or关系中,有一个真,那么结果就是出现的第一个真,那么发现真,后面的结果不会影响最终结果,所以逻辑运算结束
print(1 or 2)
print(2 or 1)
print(0 or 1)
print(1 or 0) 运算结果: 1
2
1
1
Python逻辑运算的更多相关文章
- jave 逻辑运算 vs 位运算 + Python 逻辑运算 vs 位运算
JAVA中&&和&.||和|(短路与和逻辑与.短路或和逻辑或)的区别 博客分类: 面试题目 Java.netBlog 转自 :http://blog.csdn.net/web ...
- python 逻辑运算 ‘and’ ,'or' 在实战中的作用,代替if语句。
彩票程序:课上方法:import random # 生成一个随机两位数 作为一个中奖号码luck_num = random.randint(10,99)print(luck_num)luck_num_ ...
- python逻辑运算(not,and,or)总结
逻辑运算 1.在没有()的情况下not优先级高于and,and优先级高于or,即优先级关系为()>not>and>or,同一优先级从左往右计算 总结:a or b : 如果a = 0 ...
- 测试误区《二》 python逻辑运算和关系运算优先级
关系运算 关系运算就是对2个对象进行比较,通过比较符判断进行比较,有6种方式. x > y 大于 x >= y 大于等于 x < y 小于 x <= y 小于等于 x = y ...
- python 逻辑运算及奇怪的返回值(not,and,or)
首先,'and'.'or'和'not'的优先级是not>and>or. 同一优先级从左往右计算. 先说非运算,Python的非运算与这些语言相比,并没有特别的地方.not只有两个返回值,T ...
- Python——逻辑运算(or,and)
print(0 and 2 > 1) #结果0 print(0 and 2 < 1) #结果0 print(1 and 2 > 1) #结果True print(1 and 2 &l ...
- 01 Python 逻辑运算
#基本运算符 #and or not #优先级 ()>not>and>or #and or not print(2>1 and 1<4 or 2<3 and 9&g ...
- Python数据结构与循环语句
# Python数据结构与循环语句: 首先编程是一项技能,类似跑步,期初不必在意细节,能使用起来就行,等学的游刃有余了再回过头来关注细节问题也不迟. 关于买书: 学会python之后,才需要买书 ...
- python 杂项
Python/JS/ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ...
随机推荐
- 【原创】QString 函数 replace()indexOf()、 lastindexOf()
1.替换函数 示例: QString x = "Say yes!"; QString y = "no"; x.replace(, , y); // x == & ...
- linux生成SSH key
1. 检查SSH keys是否存在 ls -al ~/.ssh2. 生成新的ssh key 输入 ssh-keygen -t rsa -C your_email@example.com
- vue-8-组件
注册 注册一个全局组件:Vue.component(tagName, options) Vue.component('my-component', { template: '<div>A ...
- 使用RxSwift 实现登录页面的条件绑定
我们在使用MVC建构进行开发时,对登录页面用户名密码等进行的处理一般是这样的,点击登录按钮判断用户框以及密码框输入的合法性,用一堆if真是屎一般!或者用textfield的代理来进行响应其实也是屎一般 ...
- 安装babel
http://jamesknelson.com/using-es6-in-the-browser-with-babel-6-and-webpack/
- python验证代理IP
接上一篇保存的IP地址,进行验证 # -*- coding: utf-8 -*- import requests from threading import Thread import threadi ...
- CentOS7安装cratedb
crate: 下载: https://crate.io/download/thank-you/?download=tar crash: 下载: https://crate.io/docs/client ...
- 开发框架DevExtreme全新发布v18.2.6|附下载
DevExtreme Complete Subscription是性能最优的 HTML5,CSS 和 JavaScript 移动.Web开发框架,可以直接在Visual Studio集成开发环境,构建 ...
- 安装ubuntu不能引导win7
台式机安装了ubuntu导致进不了win7了,2系统在同一硬盘. win7引导需要bootmgr和boot文件夹中的文件,2个东东在winows引导分区根目录下. 我的笔记本安装windows系统分区 ...
- L306 词汇题
Public acceptance of rabbit as an economical source of protein depends on how aggressively producers ...