会飞的蝌蚪君

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

 

 

#UTF编码,一个汉字对应三个字符

py2.7 字节循环

py3.5 字符循环

  1 #==============================================================================
  2 # #字符串转字符
  3 # name = "李露"
  4 # for i in name:
  5 # print(i)
  6 # byte_list = bytes(i,encoding="utf8")
  7 # print(byte_list)
  8 # for b in byte_list:
  9 # print(b,bin(b))
 10 # 
 11 # 
 12 #==============================================================================
 13 
 14 #==============================================================================
 15 # # #字节转回字符串
 16 # name = "李露"
 17 # for i in name:
 18 # print(i)
 19 # byte_list = bytes(i,encoding="utf8")
 20 # print(byte_list)
 21 # new1 = str(byte_list,encoding="utf8")
 22 # print(new1)
 23 # 
 24 # 
 25 #==============================================================================
 26 
 27 #字符串转换成列表
 28 # s1 = "李露"
 29 # s2 = list(s1)
 30 # print(s2)
 31 #==============================================================================
 32 # 
 33 # #元组转化成列表
 34 # t1 = ("al","ba","qi")
 35 # t2 = list(t1)
 36 # print(t2)
 37 #==============================================================================
 38 
 39 #字典转化成列表(可以互相转换)
 40 # dict1 = {
 41 # "name":"alex",
 42 # "age":19,
 43 # }
 44 # dict2 = dict1.items()
 45 # dict3 = list(dict2)
 46 # print(dict3)
 47 
 48 # #列表转字典
 49 # s1 = dict(dict3)
 50 # print(s1)
 51 
 52 #
 53 # li = ['alex',12,23]
 54 # temp =("as","qw","ed")
 55 # li.extend(temp)
 56 # li.reverse()
 57 # print(li)
 58 # li.insert(2,"asd")
 59 # print(li)
 60 
 61 #==============================================================================
 62 # li = ['alex',12,23]
 63 # q1 = li[1:2]
 64 # print(q1)
 65 # 
 66 #==============================================================================
 67 
 68 #列表里面嵌套字典,索引取value值
 69 
 70 #
 71 # li = ['alex',12,{'a':12,'w':{'d':21,'df':23}}]
 72 # print(li[2]['w']['df'])
 73 #
 74 
 75 ##############元组############################################################
 76 
 77 #count
 78 # t = (11,22,33,44,550)
 79 # print(t.count(11))
 80 
 81 #嵌套(元素不可修改)###元组元素本身不可修改,但嵌套后元素的元素可以修改
 82 
 83 # t = (11,22,33,['qw',12,'de'],23)
 84 # t[3].append(12)
 85 # print(t)
 86 #
 87 #
 88 
 89 #
 90 # dict = {'k1':'we','de':'ey'}
 91 # dict['ke'] = "wfr"
 92 # print(dict)
 93 # dict.update({"ge":13})
 94 # print(dict)
 95 #
 96 # ########创建 'k1',若存在此key则更新此对应value;若不存在,则新增此键值对。
 97 # dict['k1'] = 23
 98 # print(dict)
 99 #
100 #
101 
102 
103 #==============================================================================
104 # dic = {'k1':12,'k2':34}
105 # 
106 # n1 = dict.fromkeys(["k1","k2","k3"],2)
107 # print(n1)
108 #==============================================================================
109 #==============================================================================
110 # 
111 # s1 = [12,12,34]
112 # 
113 # dict_1 = dict(enumerate(s1,10))
114 # print(dict_1)
115 # 
116 # 
117 #==============================================================================
118 
119 
120 #######一般的,1)对于str,执行功能,产生新的内容
121 # 2)对于list、tuple、dict 而言,执行功能,只在原内容上进行修改。
122 
123 
124 # list_1 = list(range(100))
125 # list_2 = []
126 # list_3 = []
127 #
128 # for i in list_1:
129 # if i <= 66:
130 # list_2.append(i)
131 # elif i>66:
132 # list_3.append(i)
133 # dict_1={'k1':[],'k2':[]}
134 # dict_1['k1']=list_2
135 # dict_1['k2']=list_3
136 # print(dict_1)
137 
138 
139 '''
140 二、查找
141 
142 查找列表中元素,移除每个元素的空格,并查找以 a或A开头 并且以 c 结尾的所有元素。
143 
144 li = ["alec", " aric", "Alex", "Tony", "rain"]
145 
146 tu = ("alec", " aric", "Alex", "Tony", "rain")
147 
148 dic = {'k1': "alex", 'k2': ' aric', "k3": "Alex", "k4": "Tony"}
149 '''
150 #
151 # li = ["alec", " aric", "Alex", "Tony", "rain"]
152 #
153 # for i in li:
154 # b = i.strip()
155 # if b.startswith("a") or b.startswith("A") and b.endswith("c"):
156 # print(b)
157 #
158 
159 #
160 # tu = ("alec", " aric", "Alex", "Tony", "rain")
161 #
162 # for i in tu:
163 # b = i.strip()
164 # if b.startswith("a") or b.startswith("A") and b.endswith("c"):
165 # print(b)
166 #
167 #
168 #
169 #
170 # dic = {'k1': "alex", 'k2': ' aric', "k3": "Alex", "k4": "Tony"}
171 #
172 # for i in dic.values():
173 # b = i.strip()
174 # if b.startswith("a") or b.startswith("A") and b.endswith("c"):
175 # print(b)
176 
177 
178 '''
179 三、输出商品列表,用户输入序号,显示用户选中的商品
180 
181 商品 li = ["手机", "电脑", '鼠标垫', '游艇']
182 '''
183 '''
184 li = ["手机", "电脑", '鼠标垫', '游艇']
185 print("商品列表如下:")
186 print(li)
187 num_1 = input ('your num :')
188 print(li[int(num_1)])
189 
190 '''

 

posted on 2017-10-26 17:44  会飞的蝌蚪  阅读(177)  评论(0编辑  收藏  举报