栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python学习日记(5/24-5/25)

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python学习日记(5/24-5/25)

ONE MONTH.

一、运算符(二) 1、逻辑运算符

与and、或or、非not

应用:数字类型、字符串、列表、元组、字典

字符串:

>>> 'a' and 'b'
'b'
>>> 'a' or 'b'
'a'

>>> not ''
True
>>> not '0'
False
>>> not []
True
>>> not [0,]
False
>>> not [0]
False

>>> not ()
True
>>> not {}
True

#or:有0取非零,都是非零取前面的
>>> [1] or []
[1]
>>> [] or [1]
[1]

>>> [1] or [5]
[1]
>>> [5] or [1]
[5]
2、成员运算符

in、not in

>>> a=1
>>> a in [1,2,3,4,5]
True
>>> b=6
>>> b in [1,2,3,4,5]
False
>>> b not in [1,2,3,4,5]
True

#对字典判断的是key
>>> b = 'c'
>>> b in {'c':1}
True
>>> b in {1:'c'}
False
3、身份运算符

is、not is.is 与==作用不同,==比较数值,is比较变量的内存地址(身份)

>>> a = 1
>>> b = 2
>>> a is b
False
>>> b=1
>>> a is b
True

>>> a==b
True
>>> b=1.0
>>> a==b
True
>>> a is b
False
#is 比较变量的内存地址(身份)

>>> a = {1,2,3}
>>> b = {2,1,3}
>>> a==b
True 
#集合是无序的
>>> a is b
False

>>> c = (1,2,3)
>>> d = (1,3,2)
>>> c==d
False
#元组是有序的
>>> c is d
False

#instance
>>> a='hello'
>>> isinstance(a,str)
True
>>> isinstance(a,(int,float,str))
True
>>> isinstance(a,(int,float))
False
>>> 
4、位运算符

操作对象:数字(转为二进制数再操作)

&:按位与

|:按位或

^:按位异或

~:按位取反

<<:左移

>>:右移

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/929615.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号