蓝绝

博客园 首页 新随笔 联系 订阅 管理

随笔分类 -  python基础学习 01 图解Python语法

上一页 1 2 3 4 5 下一页

摘要:#字符串创建 可以用 单引号,双引号,和三引号 #相同的字符串,只开辟了一个空间储存,这叫字符串的驻留机制 代码中3个地址相同,只开辟了一个空间储存,这为字符串的驻留机制 #符合标识符的字符串,是指符合计算机文件命名的字符 #字符串只在编译时候进行驻留 阅读全文
posted @ 2022-09-03 20:41 蓝绝 阅读(36) 评论(0) 推荐(0)

摘要: 阅读全文
posted @ 2022-09-03 20:05 蓝绝 阅读(30) 评论(0) 推荐(0)

摘要:'''集合的生成式,集合是无序的''' s={i*4 for i in range(1,11)} print(s) {32, 4, 36, 8, 40, 12, 16, 20, 24, 28} 阅读全文
posted @ 2022-09-03 20:03 蓝绝 阅读(24) 评论(0) 推荐(0)

摘要:总知识点:# 交集操作(集合的相同元素),注意操作后的原集合不会发生变化 intersection() 符号 &# 并集操作(集合的元素和) union() 符号 |# 差集合操作(集合减去相同部分,集合相减有先后顺序) difference() 符号 -#对称差集操作,反差集操作(集合减去相同部分 阅读全文
posted @ 2022-09-03 19:52 蓝绝 阅读(458) 评论(0) 推荐(0)

摘要:s1={10,20,30,40,50,70} s2={20,10,30,40,50,70} s3={20,10,30,40} '''两个集合是否相等''' print(s1==s2) #Ture print(s1!=s2) #False '''一个集合是否是另一个集合的子集''' print(s3. 阅读全文
posted @ 2022-09-03 13:02 蓝绝 阅读(28) 评论(0) 推荐(0)

摘要:s={10,20,30,40,50,70} '''集合的判断操作''' print(10 in s) #True print(10 not in s) #False True False #集合元素的新增操作。add() 一次添加一个元素. update() 一次添加多个元素 s={10,20,30 阅读全文
posted @ 2022-09-03 11:43 蓝绝 阅读(48) 评论(0) 推荐(0)

摘要:#注意: 1.集合元素不能重复,重复的话结果会去掉重复元素2.集合是无序的,和字典一样 '''集合的创建方式''' '''集合的创建的第一种方式,用{}''' '''注意由于{}与字典符号相同,创建空集合时要用函数set()创建''' t={1,1,2,2,3,3,4,4} print(t) #集合 阅读全文
posted @ 2022-09-02 12:10 蓝绝 阅读(177) 评论(0) 推荐(0)

摘要:'''元组的遍历''' t2=('Python','world',98) for item in t2: print(item) E:\PycharmProjects\pythonProject\venv\Scripts\python.exe E:/PycharmProjects/pythonPro 阅读全文
posted @ 2022-09-02 11:07 蓝绝 阅读(22) 评论(0) 推荐(0)

摘要:''' 元组中对象本身是不可变对象。如果其中对象为可变对象,引用不可改变,但是数据可以改变''' t=(10,[20,30],9) print(id(t[2])) #改变前id t[1].append(20) print(t) print(id(t[2])) #改变后id,数据变了,但id没变 E: 阅读全文
posted @ 2022-09-02 11:01 蓝绝 阅读(29) 评论(0) 推荐(0)

摘要:'''第一种创建方式,使用()''' t=('Python','world',98) print(t) print(type(t)) '''第二种创建方式,使用内置函数tuple()''' t1=tuple(('Python','world',98)) #注意需要2个小括号 print(t1) pr 阅读全文
posted @ 2022-09-02 10:09 蓝绝 阅读(63) 评论(0) 推荐(0)

摘要:#注意判断是否是可变序列,主要是看地址是否发生改变 阅读全文
posted @ 2022-08-31 19:01 蓝绝 阅读(28) 评论(0) 推荐(0)

摘要: 阅读全文
posted @ 2022-08-31 15:02 蓝绝 阅读(20) 评论(0) 推荐(0)

摘要:'''字典的生成式,zip()为打包函数''' items=['Fruits','Books','Others'] prices=[96,78,100] d={item.upper():price for item,price in zip(items,prices)}#upper()为大写字母函数 阅读全文
posted @ 2022-08-31 15:01 蓝绝 阅读(34) 评论(0) 推荐(0)

摘要:'''字典的值可以是相同的''' scores={'张三':100,'李四':100,'王五':100} print(scores['李四']) print(scores['张三']) '''字典的key不能是相同的''' scores1={'张三':101,'张三':102,'张三':103} p 阅读全文
posted @ 2022-08-31 14:39 蓝绝 阅读(37) 评论(0) 推荐(0)

摘要:'''字典的遍历''' scores={'张三':100,'李四':98,'王五':45} for item in scores: print(item,scores[item],scores.get(item)) #获取分别是键 和 值 E:\PycharmProjects\pythonProje 阅读全文
posted @ 2022-08-31 14:15 蓝绝 阅读(23) 评论(0) 推荐(0)

摘要:scores={'张三':100,'李四':98,'王五':45} '''获取所有的key''' print() #让结果隔行 keys=scores.keys() print(keys) print(type(keys)) print(list(keys)) #所有的key组成的视图转成列表 '' 阅读全文
posted @ 2022-08-30 16:14 蓝绝 阅读(28) 评论(0) 推荐(0)

摘要:'''key 的判断''' scores={'张三':100,'李四':98,'王五':45} print('张三' in scores) print('张三' not in scores) '''删除指定的key-value对''' del scores['张三'] print(scores) ' 阅读全文
posted @ 2022-08-30 14:52 蓝绝 阅读(28) 评论(0) 推荐(0)

摘要:'''字典元素的获取''' '''第一种 使用[]''' #注意[]里没有的元素会报错 scores={'张三':100,'李四':98,'王五':45} print(scores['张三']) '''第二种 使用get()函数''' #注意[]里没有的元素会输出None print(scores. 阅读全文
posted @ 2022-08-29 12:12 蓝绝 阅读(58) 评论(0) 推荐(0)

摘要:''' 使用{}创建字典''' scores={'张三':100,'李四':98,'王五':45} print(scores) '''第二种创建''' student=dict(name='jact',age=20) print(student) '''空字典创建''' d={} print(d) 阅读全文
posted @ 2022-08-29 11:40 蓝绝 阅读(39) 评论(0) 推荐(0)

摘要:和语文查字典一样, 计算机通过哈希函数(hash函数)寻找值 阅读全文
posted @ 2022-08-29 11:27 蓝绝 阅读(37) 评论(0) 推荐(0)

上一页 1 2 3 4 5 下一页