【九月打卡】第5天Python第五章变量与运算符
2022/9/10 3:23:11
本文主要是介绍【九月打卡】第5天Python第五章变量与运算符,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
课程名称:全面系统Python3.8入门+进阶(程序员必备第二语言)
课程章节: 5-10 成员运算符 5-11 身份运算符
主讲老师:7七月
课程内容:
今天学习的内容包括:
成员运算符
身份运算符
课程收获:
5-10 成员运算符
在 ,不在
a = 1
a 是否在[1,2,3,4,5]
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
b = 'h'
b in 'hello' ---- True
b not in (1,2,3,4,5)----True
b not in {1,2,3,4,5} ----True
字典的成员运算符
b = 'a'
b in {'c':1}-----False
b = 1
b in {'c':1} ------False
b = 'c'
b in {'c':1} ----- True
#规律:说明,字典的成员运算时肯定key:value 键值对立面的键来判断的。他判断的是key。
5-11 身份运算符
<article data-content="[{"type":"block","id":"KUPs-1661762456081","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"c7DM-1661762456080","leaves":[{"text":"最终返回结果同样是布尔值。","marks":[]}]}],"state":{}},{"type":"block","id":"NInm-1661762505974","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"RxYN-1661762505973","leaves":[{"text":"a = 1","marks":[]}]}],"state":{}},{"type":"block","id":"EeVc-1661762514728","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"nWoo-1661762514727","leaves":[{"text":"b =2","marks":[]}]}],"state":{}},{"type":"block","id":"7Wb2-1661762522395","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"Y2Kf-1661762522393","leaves":[{"text":"a is b ----- False","marks":[]}]}],"state":{}},{"type":"block","id":"QnGz-1661762629243","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"vlQd-1661762629241","leaves":[{"text":"a = 1","marks":[{"type":"color","value":"#403ED6"}]}]}],"state":{}},{"type":"block","id":"GPz0-1661762634787","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"Md4i-1661762634786","leaves":[{"text":"b =1","marks":[{"type":"color","value":"#403ED6"}]}]}],"state":{}},{"type":"block","id":"wi9j-1661762637846","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"fVnz-1661762637844","leaves":[{"text":"a is b ------True","marks":[{"type":"color","value":"#403ED6"}]}]}],"state":{}},{"type":"block","id":"1wAC-1661762645016","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"m3gJ-1661762645014","leaves":[{"text":"a = " hello'","marks":[{"type":"color","value":"#403ed6"}]}]}],"state":{}},{"type":"block","id":"ebpa-1661762652105","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"40jn-1661762652104","leaves":[{"text":"b="world" ","marks":[]}]}],"state":{}},{"type":"block","id":"twsm-1661762657652","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"mr4j-1661762657650","leaves":[{"text":"a="" is="" b="" -----false","marks":[]}]}],"state":{}},{"type":"block","id":"igjt-1661762664718","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"b2cf-1661762664716","leaves":[{"text":"c="hello" ","marks":[{"type":"color","value":"#403ed6"}]}]}],"state":{}},{"type":"block","id":"ogts-1661762672920","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"0vrv-1661762672919","leaves":[{"text":"a="" c="" ------true","marks":[{"type":"color","value":"#403ed6"}]}]}],"state":{}},{"type":"block","id":"irzi-1661762528428","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"bapv-1661762528427","leaves":[{"text":"2个变量他们的取值相等的时候,身份运算符才会返回true。","marks":[]}]}],"state":{}},{"type":"block","id":"gzup-1661762681577","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"ayum-1661762681576","leaves":[{"text":"is="" 和关系运算符="=有什么区别。","marks":[]}]}],"state":{}},{"type":"block","id":"l0qk-1661762759425","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"g2RN-1661762759423","leaves":[{"text":"a" =="" 1","marks":[{"type":"color","value":"#403ed6"}]}]}],"state":{}},{"type":"block","id":"plca-1661762759763","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"2oj2-1661762759764","leaves":[{"text":"b="1","marks":[{"type":"color","value":"#403ED6"}]}]}],"state":{}},{"type":"block","id":"6ZHJ-1661762759765","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"Octq-1661762759766","leaves":[{"text":"a" ------true","marks":[{"type":"color","value":"#403ed6"}]}]}],"state":{}},{"type":"block","id":"b1el-1661762761507","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"wxmb-1661762761506","leaves":[{"text":"a="=" -----true","marks":[{"type":"color","value":"#403ed6"}]}]}],"state":{}},{"type":"block","id":"vkgb-1661762768214","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"tjtf-1661762768212","leaves":[{"text":"a="1","marks":[{"type":"color","value":"#FF0001"}]}]}],"state":{}},{"type":"block","id":"BCL2-1661762771959","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"gnAQ-1661762771958","leaves":[{"text":"b" 1.0","marks":[{"type":"color","value":"#ff0001"}]}]}],"state":{}},{"type":"block","id":"mmce-1661762781309","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"bdxx-1661762781307","leaves":[{"text":"a="=" ----true","marks":[{"type":"color","value":"#ff0001"}]}]}],"state":{}},{"type":"block","id":"1mof-1661762794802","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"kzjc-1661762794800","leaves":[{"text":"a="" ----false","marks":[{"type":"color","value":"#ff0001"}]}]}],"state":{}},{"type":"block","id":"wdkj-1661762799621","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"1qe4-1661762799620","leaves":[{"text":"is和="=" 还是有区别的,关系运算符他所比较的是2个变量的值是否相等;is他不是比较值相等,他比较是2个变量身份是否相等。内存地址是否相等。","marks":[{"type":"color","value":"#ff0001"}]}]}],"state":{}},{"type":"block","id":"cqk8-1661762891490","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"uumg-1661762891489","leaves":[{"text":"id(a)="" -----1825007744","marks":[{"type":"color","value":"#ff0001"}]}]}],"state":{}},{"type":"block","id":"qoc9-1661762904414","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"su5p-1661762904412","leaves":[{"text":"id(b)="" ----68997248","marks":[{"type":"color","value":"#ff0001"}]}]}],"state":{}},{"type":"block","id":"fn0p-1661762919544","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"bzue-1661762919543","leaves":[{"text":"is="" 一个变量的身份是否和另一个变量相等,not="" 一个变量的身份是否和另一个变相不等。","marks":[{"type":"color","value":"#6ddeff"}]}]}],"state":{}},{"type":"block","id":"yzet-1661763114403","name":"paragraph","data":{"version":1},"nodes":[{"type":"text","id":"1ara-1661763114402","leaves":[{"text":"集合是无序的{},元组属于序列他是有序的。所以="=ab为True,cd为False","marks":[{"type":"color","value":"#6DDEFF"}]}]}],"state":{}}]'">
最终返回结果同样是布尔值。
a = 1
b =2
a is b ----- False
a = 1
b =1
a is b ------True
a = 'hello'
b = 'world'
a is b -----False
c = 'hello'
a is c ------True
2个变量他们的取值相等的时候,身份运算符才会返回True。
is 和关系运算符==有什么区别。
a = 1
b =1
a is b ------True
a == b -----True
a = 1
b = 1.0
a == b ----True
a is b ----False
is和== 还是有区别的,关系运算符他所比较的是2个变量的值是否相等;is他不是比较值相等,他比较是2个变量身份是否相等。内存地址是否相等。
id(a) -----1825007744
id(b) ----68997248
is 一个变量的身份是否和另一个变量相等,not is 一个变量的身份是否和另一个变相不等。
集合是无序的{},元组属于序列他是有序的。所以==ab为True,cd为False
这篇关于【九月打卡】第5天Python第五章变量与运算符的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-12-24Python编程入门指南
- 2024-12-24Python编程基础入门
- 2024-12-24Python编程基础:变量与数据类型
- 2024-12-23使用python部署一个usdt合约,部署自己的usdt稳定币
- 2024-12-20Python编程入门指南
- 2024-12-20Python编程基础与进阶
- 2024-12-19Python基础编程教程
- 2024-12-19python 文件的后缀名是什么 怎么运行一个python文件?-icode9专业技术文章分享
- 2024-12-19使用python 把docx转为pdf文件有哪些方法?-icode9专业技术文章分享
- 2024-12-19python怎么更换换pip的源镜像?-icode9专业技术文章分享