2015年5月7日
平谷 5点起床——6点20的852——7点36:东直门——8点20:西二旗——9点08:沙河教室
各种实用技巧展示,各种精良插件推荐,各种炫酷技能介绍。
Live Template 和 远程调试功能统统都有,不看绝对后悔系列!
点击下方链接让你重新认识PyCharm!
51CTO链接:http://edu.51cto.com/course/course_id-9043.html
优酷链接:http://v.youku.com/v_show/id_XMjczOTM4MzE2MA==.html
一、进制
a、二进制——01
b、八进制——0 1 2 3 4 5 6 7 8 10
c、十进制——0 1 2 3 4 5 6 7 8 9 10
d、十六进制——0 1 2 3 4 5 6 7 8 9 A B C D E F——/X0f
- 0 1位
- 0101000 1字节
- 0101000 0101000 unicode
—utf-8 李 0101000 0101000 0101000
-gbk 李 0101000 0101000
总结:
-硬盘上保存数据:0101000010100001010000101000
—读取:010100001010000101000—》对应的编码 —》 xx
—看到:
- 转换完成的字符串
- 以十六进制展示的0101000
二、数据类型
a、字符串——str——‘’,“”,“”“ ”“”——sname = ‘alex’:类str的对象
-是否以xx开头
1 name = 'alex' 2 v = name.startswith('al') 3 print(v)
—是否以xx结尾
1 name = 'alex' 2 v = name.endswith('al') 3 print(v)
-首字母大写
1 # name = 'alex' # str类的对象 2 # 1. capitalize 字符串首字母大写 3 # 自身不变,会生成一个新的值 4 # v = name.capitalize() # 自动找到name关联的str类,执行其中的capitalize技能 5 # print(name) 6 # print(v)
-将所有大写变小写,casefold,包括很多语言(德语等)---我是没看到这个
1 将所有大小变小写,casefold牛逼,德语... 2 # name = 'AleX' 3 # v = name.casefold() # 跟牛逼,德语... 4 # print(name) 5 # print(v)
-又一个大写变小写,只涉及英文
1 将所有大小变小写 2 # name = 'AleX' 3 # v = name.lower() 4 # print(v)
-文本居中——center莫属:a、参数一表示总长度;b、空白处填充的字符(长度为1)
1 name = 'alex' 2 v = name.center(20) 3 print(v) 4 v = name.center(20,'行') 5 print(v)
-表示传入值在字符串中出现的次数--count:参数一、要查找的值(子序列);参数二、起始位置(索引);参数三、结束位置(索引)
1 name = "alexasdfdsafsdfasdfaaaaaaaa" 2 v = name.count('a') 3 print(v) 4 v = name.count('df') 5 print(v) 6 7 v = name.count('df',12) 8 print(v) 9 10 v = name.count('df',0,15) 11 print(v)
-找到制表符\t,进行替换(包含前面的值)
1 name = "al\te\tx\nalex\tuu\tkkk" 2 v = name.expandtabs(20) 3 print(v)
-找到置顶子序列的索引位置,不存在的返回-1
1 name = 'alex' 2 v = name.find('o') #找到指定索引位置,不存在返回-1 3 print(v) 4 v = name.index('o') #找到指定索引位置,不存在报错 5 print(v)
-字符串格式化
1 tpl = "我是:%s;年龄:%s;性别:%s",% (‘李杰’,19,'男') 2 3 tpl = "我是:{0};年龄:{1};性别:{2}" 4 v = tpl.format("李杰",19,‘都行’) 5 print(v) 6 7 tel = "我是:{name};年龄:{age};性别:{gender}" 8 v = tpl.format(name='李杰‘,age=19,gender='随意') 9 print(v) 10 v2 = tpl.format_map({'name':"李杰",'age':19,'gender':'中'}) 11 print(v2)
-是否是数字、汉字
1 name = 'alex8汉子' 2 v = name.isalnum() #字、数字 3 print(v) # True 4 v2 = name.isalpha() 5 print(v2) # False 6
-判断是否是数字
1 num = '②' 2 v1 = num.isdecimal() # '123' 3 v2 = num.isdigit() # '123','②' 4 v3 = num.isnumeric() # '123','二','②' 5 print(v1,v2,v3)
-是否是表示符
1 n = 'name' 2 v = n.isidentifier() 3 print(v)
-是否全部是小写
1 name = 'ALEX' 2 v = name.islower() #是否是小写 3 print(v) 4 v = name.isupper() #是否是大写 5 print(v)
-全部变大写
1 name = 'alex' 2 v = name.upper() 3 print(v)
-是否包含隐含的xx
1 name = "钓鱼要钓刀鱼,\n刀鱼要到岛上钓" 2 v = name.isprintable() 3 print(v)
-是否全部是空格
1 name = ' '2 v = name.isspace() 3 print(v)
-元素拼接(元素字符串)
1 name = 'alex' 2 v = '_'.join(name) #内部循环每个元素 3 print(v) 4 5 name_list = ['海峰','杠娘','李杰','李泉'] 6 v = "搞".join(name_list) 7 print(v)
-左右填充center,rjust,ljust
1 name = 'alex' 2 v = name.rjust(20,'*') 3 print(v)
-对应关系+翻译
1 m = str.maketrans('aeiou','12345') # 对应关系 2 name = "akpsojfasdufasdlkfj8ausdfakjsdfl;kjer09asdf" 3 v = name.translate(m) 4 print(v)
-分割,保留分割的元素
1 content = "李泉SB刘康SB刘一" 2 v = content.partition('SB') # partition 3 print(v)
-替换
1 content = "李泉SB刘康SB刘浩SB刘一" 2 v = content.replace('SB','Love') 3 print(v) 4 v = content.replace('SB','Love',1) 5 print(v)
-移除空白,\n,\t,自定义
1 name = 'alex\t' 2 v = name.strip() # 空白,\n,\t 3 print(v)
-大小写转换
1 name = "Alex" 2 v = name.swapcase() 3 print(v)
-填充0
1 # name = "alex" 2 # v = name.zfill(20) 3 # print(v) 4 5 # v1 = 'alex' 6 # v2 = 'eric' 7 # 8 # v = v1 + v2 # 执行v1的__add__功能 9 # print(v)
总结
1 ###### 字符串功能总结: 2 # name = 'alex' 3 # name.upper() 4 # name.lower() 5 # name.split() 6 # name.find() 7 # name.strip() 8 # name.startswith() 9 # name.format() 10 # name.replace() 11 # "alex".join(["aa",'bb']) 12 13 14 ###### 额外功能: 15 # name = "alex" 16 # name[0] 17 # name[0:3] 18 # name[0:3:2] 19 # len(name) 20 # for循环,每个元素是字符
b、整数——int——不可变类型
1 # 1. 当前整数的二进制表示,最少位数 2 # age = 4 # 100 3 # print(age.bit_length()) 4 5 # 2. 获取当前数据的字节表示 6 # age = 15 7 # v = age.to_bytes(10,byteorder='big') 8 # v = age.to_bytes(10,byteorder='little') 9 # print(v) 10 # 00000000 00001111 -> 15
c、列表——list——[‘alex’,‘eric’]
1 # ## int=xx; str='xxx' list='xx' 2 # user_list = ['李泉','刘一','刘康','豆豆','小龙'] # 可变类型 3 # PS: 4 # name = 'alex' 5 # 执行功能; 6 # 1.追加 7 # user_list = ['李泉','刘一','刘康','豆豆','小龙'] # 可变类型 8 # user_list.append('刘铭') 9 # print(user_list) 10 # 2. 清空 11 # user_list = ['李泉','刘一','刘康','豆豆','小龙'] # 可变类型 12 # user_list.clear() 13 # print(user_list) 14 15 # 3. 拷贝(浅拷贝) 16 # user_list = ['李泉','刘一','刘康','豆豆','小龙'] # 可变类型 17 # v = user_list.copy() 18 # print(v) 19 # print(user_list) 20 21 # 4. 计数 22 # user_list = ['李泉','刘一','李泉','刘康','豆豆','小龙'] # 可变类型 23 # v = user_list.count('李泉') 24 # print(v) 25 26 # 5. 扩展原列表 27 # user_list = ['李泉','刘一','李泉','刘康','豆豆','小龙'] # 可变类型 28 # user_list.extend(['郭少龙','郭少霞']) 29 # print(user_list) 30 31 # 6. 查找元素索引,没有报错 32 # user_list = ['李泉','刘一','李泉','刘康','豆豆','小龙'] # 可变类型 33 # v = user_list.index('李海') 34 # print(v) 35 36 # 7. 删除并且获取元素 - 索引 37 # user_list = ['李泉','刘一','李泉','刘康','豆豆','小龙'] # 可变类型 38 # v = user_list.pop(1) 39 # print(v) 40 # print(user_list) 41 42 # 8. 删除 - 值 43 # user_list = ['李泉','刘一','李泉','刘康','豆豆','小龙'] # 可变类型 44 # user_list.remove('刘一') 45 # print(user_list) 46 47 # 9. 翻转 48 # user_list = ['李泉','刘一','李泉','刘康','豆豆','小龙'] # 可变类型 49 # user_list.reverse() 50 # print(user_list) 51 52 # 10. 排序: 欠参数 53 # nums = [11,22,3,3,9,88] 54 # print(nums) 55 # 排序,从小到大 56 # nums.sort() 57 # print(nums) 58 # 从大到小 59 # nums.sort(reverse=True) 60 # print(nums) 61 62 ###### 额外: 63 # user_list = ['李泉','刘一','李泉','刘康','豆豆','小龙'] 64 # user_list[0] 65 # user_list[1:5:2] 66 # del user_list[3] 67 # for i in user_list: 68 # print(i) 69 # user_list[1] = '姜日天' 70 # user_list = ['李泉','刘一','李泉','刘康','豆豆',['日天','日地','泰迪'],'小龙'] 71 72 73 # li = ['eric','alex','tony'] 74 # 75 # v = len(li) 76 # print(v) 77 # 78 # li.append('seven') 79 # print(li) 80 # 81 # li.insert(0,'Tony') 82 # print(li) 83 # 84 # li[1] = 'Kelly' 85 # 86 # li.remove('eric') 87 # print(list) 88 # 89 # v = li.pop(1) 90 # print(v) 91 # print(li) 92 # 93 # del li[2] 94 95 96 # del li[0:2] # 0 =<x < 2 97 # print(li) 98 99 # li.reverse() 100 # print(li) 101 102 # for i in li: 103 # print(i) 104 105 # ######################################### 强插:range,enumrate ######################################### 106 # 1. 请输出1-10 107 # 2.7: 立即生成所有数字 108 # range(1,11) # 生成 1,23,,4,56.10 109 110 # 3.x: 不会立即生成,只有循环迭代时,才一个一个生成 111 # for i in range(1,11): # 112 # print(i) 113 114 # for i in range(1,11,2): # 115 # print(i) 116 117 # for i in range(10,0,-1): # 118 # print(i) 119 120 # 1. 3.x 不会立生成,迭代之后才一个一个创建; 121 """ 122 - 2.7: 123 range() 124 xrange() 不会立生成,迭代之后才一个一个创建; 125 - 3.x 126 range() 不会立生成,迭代之后才一个一个创建; 127 """ 128 # 2. range: 三个参数 129 # 130 # li = ['eric','alex','tony'] 131 # # range,len,li循环 132 # for i in range(0,len(li)): 133 # ele = li[i] 134 # print(ele) 135 136 137 # li = ['eric','alex','tony'] 138 # for i in li: 139 # print(i) 140 141 # for i in range(0,len(li)): 142 # print(i+1,li[i]) 143 144 145 # enumerate额外生成一列有序的数字 146 # li = ['eric','alex','tony'] 147 # for i,ele in enumerate(li,1): 148 # print(i,ele) 149 # 150 # v = input('请输入商品序号:') 151 # v = int(v) 152 # item = li[v-1] 153 # print(item)
d、字典——dict——{‘name’:‘alex’,‘name’:‘eric’}
1 # 1. 清空、 2 # dic = {'k1':'v1','k2':'v2'} 3 # dic.clear() 4 # print(dic) 5 6 # 2. 浅拷贝 7 # dic = {'k1':'v1','k2':'v2'} 8 # v = dic.copy() 9 # print(v) 10 11 # 3. 根据key获取指定的value;不存在不报错 12 # dic = {'k1':'v1','k2':'v2'} 13 # v = dic.get('k1111',1111) 14 # print(v) 15 # v = dic['k1111'] 16 # print(v) 17 18 # 4. 删除并获取对应的value值 19 # dic = {'k1':'v1','k2':'v2'} 20 # v = dic.pop('k1') 21 # print(dic) 22 # print(v) 23 24 # 5. 随机删除键值对,并获取到删除的键值 25 # dic = {'k1':'v1','k2':'v2'} 26 # v = dic.popitem() 27 # print(dic) 28 # print(v) 29 30 # k,v = dic.popitem() # ('k2', 'v2') 31 # print(dic) 32 # print(k,v) 33 34 # v = dic.popitem() # ('k2', 'v2') 35 # print(dic) 36 # print(v[0],v[1]) 37 38 # 6. 增加,如果存在则不做操作 39 # dic = {'k1':'v1','k2':'v2'} 40 # dic.setdefault('k3','v3') 41 # print(dic) 42 # dic.setdefault('k1','1111111') 43 # print(dic) 44 # 7. 批量增加或修改 45 # dic = {'k1':'v1','k2':'v2'} 46 # dic.update({'k3':'v3','k1':'v24'}) 47 # print(dic) 48 49 50 # dic = dict.fromkeys(['k1','k2','k3'],123) 51 # print(dic) 52 # dic = dict.fromkeys(['k1','k2','k3'],123) 53 # dic['k1'] = 'asdfjasldkf' 54 # print(dic) 55 56 # dic = dict.fromkeys(['k1','k2','k3'],[1,]) 57 # { 58 # k1: 123123213, # [1,2] 59 # k2: 123123213, # [1,] 60 # k3: 123123213, # [1,] 61 # } 62 # dic['k1'].append(222) 63 # print(dic) 64 # ########## 额外: 65 # - 字典可以嵌套 66 # - 字典key: 必须是不可变类型 67 # dic = { 68 # 'k1': 'v1', 69 # 'k2': [1,2,3,], 70 # (1,2): 'lllll', 71 # 1: 'fffffffff', 72 # 111: 'asdf', 73 # } 74 # print(dic) 75 # key: 76 # - 不可变 77 # - True,1 78 79 # dic = {'k1':'v1'} 80 # del dic['k1'] 81 82 # 布尔值: 83 # 1 True 84 # 0 False 85 # 86 # bool(1111)
e、集合——set——{‘alex’,‘eric’}——不可变类型
1 s1 = {"alex",'eric','tony','李泉','李泉11'} 2 # s2 = {"alex",'eric','tony','刘一'} 3 4 # 1.s1中存在,s2中不存在 5 # v = s1.difference(s2) 6 # print(v) 7 # #### s1中存在,s2中不存在,然后对s1清空,然后在重新复制 8 # s1.difference_update(s2) 9 # print(s1) 10 11 # 2.s2中存在,s1中不存在 12 # v = s2.difference(s1) 13 # print(v) 14 15 # 3.s2中存在,s1中不存在 16 # s1中存在,s2中不存在 17 # v = s1.symmetric_difference(s2) 18 # print(v) 19 # 4. 交集 20 # v = s1.intersection(s2) 21 # print(v) 22 # 5. 并集 23 # v = s1.union(s2) 24 # print(v) 25 26 # 6. 移除 27 # s1 = {"alex",'eric','tony','李泉','李泉11'} 28 # s1.discard('alex') 29 # print(s1) 30 31 # s1 = {"alex",'eric','tony','李泉','李泉11'} 32 # s1.update({'alex','123123','fff'}) 33 # print(s1) 34 # ##### 额外: 35 36 # s1 = {"alex",'eric','tony','李泉','李泉11'} 37 # for i in s1: 38 # print(i) 39 40 # s1 = {"alex",'eric','tony','李泉','李泉11',(11,22,33)} 41 # for i in s1: 42 # print(i)
f、元组——tuple——(‘alex’,‘eric’)——不可变类型
1 # user_tuple = ('alex','eric','seven','alex') 2 # 1. 获取个数 3 # v = user_tuple.count('alex') 4 # print(v) 5 # 2.获取值的第一个索引位置 6 # v = user_tuple.index('alex') 7 # print(v) 8 9 ####### 额外: 10 # user_tuple = ('alex','eric','seven','alex') 11 # for i in user_tuple: 12 # print(i) 13 14 # v = user_tuple[0] 15 16 # v = user_tuple[0:2] 17 # print(v) 18 19 # user_tuple = ('alex','eric','seven',['陈涛','刘浩','赵芬芬'],'alex') 20 # user_tuple[0] = 123 x 21 # user_tuple[3] = [11,22,33] x 22 # user_tuple[3][1] = '刘一' 23 # print(user_tuple) 24 25 # li = ['陈涛','刘浩',('alex','eric','seven'),'赵芬芬'] 26 # ****** 元组最后,加逗号 ****** 27 # li = ('alex',) 28 # print(li)
g、布尔值——bool——1:True & 0:False
1 # v = 0 # 1,-1 2 # v = "" 3 # v = [] 4 # --> 空内容:False
疑惑;set集合的 discard,remove,pop的区别