摘要: # 嵌套 dic = { 'name':'汪峰', 'age':48, 'wife':[{'name':'国际章','age':38}], 'children':{'girl_first':'小苹果','girl_second':'小怡','girl_three':'顶顶'} } # 1. 获取汪峰 阅读全文
posted @ 2020-07-15 16:07 XuanchenLi 阅读(385) 评论(0) 推荐(0) 编辑
摘要: # (1)字典的增 # 通过键值对直接增加 # 有键值则覆盖,如果没有键值则添加 dic = {'ni':1,'woazia':2} dic['hello'] = 6 # 没有'hello'这个键,就增加键值对 print(dic) # {'ni': 1, 'woazia': 2, 'hello': 阅读全文
posted @ 2020-07-15 16:05 XuanchenLi 阅读(181) 评论(0) 推荐(0) 编辑
摘要: #字典 的有效性 {key:value} key hashable 可哈希的 # 不可变 str int tuple bool 合法运用到字典 key # 可变 list dict set 不合法运用到字典 key # hashable 不可变 dic = {'n':1} dic = {1:2} d 阅读全文
posted @ 2020-07-15 16:00 XuanchenLi 阅读(181) 评论(0) 推荐(0) 编辑
摘要: # 字典 #{} dic = {} print(dic) print(type(dic)) # <class 'dict'> # 语法格式 {'xuann':2,'lic':65} # key 键 # value 值 # 键值对 一个元素 # 1:创建字典 d1 = dict() print(d1) 阅读全文
posted @ 2020-07-14 11:19 XuanchenLi 阅读(3030) 评论(0) 推荐(0) 编辑
摘要: user = ['xuan','chen'] passed = ['159','564'] s1 = ''' '1).注册新用户' '2).用户登录' '3).注销用户' '4).显示用户名' '5).修改用户信息' '6).退出系统(exit(0))' ''' while 1: print(s1) 阅读全文
posted @ 2020-07-13 20:15 XuanchenLi 阅读(109) 评论(0) 推荐(0) 编辑
摘要: # count 推导思路 l1 = [1,2,3,5,4,1,2,3,6,4,5,88,99] l2 = list() # [元素,次数,元素,次数,..........................] for i in l1: # i 在 l1 循环 if i not in l2: # 条件 : 阅读全文
posted @ 2020-07-13 11:18 XuanchenLi 阅读(151) 评论(0) 推荐(0) 编辑
摘要: # len 长度 迭代 s1 = "nihaoma" print(len(s1)) # list s1 的长度 # len 的运用 i = 0 while i < len(s1): print(s1[i]) i+=1 #s1.count 总 数 查看出现的次数 #s1.startswith 判断是否 阅读全文
posted @ 2020-07-10 21:01 XuanchenLi 阅读(347) 评论(0) 推荐(0) 编辑
摘要: # 字符串 # " " '' 借助函数 。 .format() %。......... s1 = "nihao" # 索引--index [] print(s1[0]) print(s1[1]) print(s1[2]) print(s1[3]) print(s1[4]) # n # i # h # 阅读全文
posted @ 2020-07-10 20:38 XuanchenLi 阅读(317) 评论(0) 推荐(0) 编辑
摘要: # List 应用 # 方式一: List_01 = [1,23,2] print(List_01) #[‘1’, ‘23’ ,’2’] # 方法二: # 加入可迭代对象 list_01 = list(iterable) s1 = list('1516741niabjihbu') print(s1) 阅读全文
posted @ 2020-07-10 20:19 XuanchenLi 阅读(666) 评论(0) 推荐(0) 编辑
摘要: # 求和 l = [88,97,79,89,76] re = 0 for i in l: re += 1 print(re//5) # 平均值 # print(sum(l)) # he print(max(l)) # max # max 推演思路 #默认第一个值最大 打擂 l[0] # 后边的元素和 阅读全文
posted @ 2020-07-10 19:54 XuanchenLi 阅读(189) 评论(0) 推荐(0) 编辑