摘要: 1 f = open('C:/Users/Administrator/Desktop/100.txt', 'rb') 2 data = f.read() 3 # print(data) 4 f.close() 5 6 import chardet 7 print(chardet.detect(data)) 8 print(data.decode('ascii')) 9 10... 阅读全文
posted @ 2018-01-11 22:44 jonm 阅读(202) 评论(0) 推荐(0) 编辑
摘要: 1 s = "I am fine" 2 s = s.split(" ") 3 print(s) 4 print("%".join(s)) 5 6 results: 7 8 ['I', 'am', 'fine'] 9 I%am%fine 阅读全文
posted @ 2018-01-11 20:49 jonm 阅读(192) 评论(0) 推荐(0) 编辑
摘要: 开始--运行--cmd 进入命令提示符 输入netstat -aon 即可看到所有连接的PID 之后在任务管理器中找到这个PID所对应的程序如果任务管理器中没有PID这一项,可以在任务管理器中选"查看"-"选择列" 经常,我们在启动应用的时候发现系统需要的端口被别的程序占用,如何知道谁占有了我们需要 阅读全文
posted @ 2018-01-11 20:17 jonm 阅读(9256) 评论(0) 推荐(0) 编辑
摘要: Python中的strip用于去除字符串的首位字符,同理,lstrip用于去除左边的字符,rstrip用于去除右边的字符。这三个函数都可传入一个参数,指定要去除的首尾字符。注意的是,传入的是一个字符数组,编译器去除两端所有相应的字符,直到没有匹配的字符,比如: theString依次被去除首尾在[' 阅读全文
posted @ 2018-01-11 20:15 jonm 阅读(436) 评论(0) 推荐(0) 编辑
摘要: join 方法用于连接字符串数组 使用 % 连接多个变量 阅读全文
posted @ 2018-01-11 20:07 jonm 阅读(26826) 评论(0) 推荐(0) 编辑
摘要: 和其他语言一样,Python为string对象提供了转换大小写的方法:upper() 和 lower()。还不止这些,Python还为我们提供了首字母大写,其余小写的capitalize()方法,以及所有单词首字母大写,其余小写的title()方法。函数较简单,看下面的例子: 判断大小写 Pytho 阅读全文
posted @ 2018-01-11 19:53 jonm 阅读(15169) 评论(0) 推荐(0) 编辑
摘要: Python中的splitlines用来分割行。当传入的参数为True时,表示保留换行符 \n。通过下面的例子就很明白了: 阅读全文
posted @ 2018-01-11 19:45 jonm 阅读(401) 评论(0) 推荐(0) 编辑
摘要: 1 array = [1, 6, 7, 2, 9, 4] 2 for i in range(len(array)-1, 1, -1): 3 for j in range(0, i): 4 if array[j] > array[j+1]: 5 array[j], array[j+1] = array[j+1], array[j] 6 p... 阅读全文
posted @ 2018-01-11 18:33 jonm 阅读(1128) 评论(0) 推荐(0) 编辑
摘要: 1 >>>print ord("a") 2 97 3 >>>print chr(97) 4 a 阅读全文
posted @ 2018-01-11 18:23 jonm 阅读(267) 评论(0) 推荐(0) 编辑
摘要: Python中打印字符串时可以调用ljust(左对齐),rjust(右对齐),center(中间对齐)来输出整齐美观的字符串,使用起来非常简单,包括使用第二个参数填充(默认为空格)。看下面的例子就会明白了: attention: '|'与'*'为逗号,'*'与ljust()间为点号 repr函数和反 阅读全文
posted @ 2018-01-11 18:20 jonm 阅读(219) 评论(0) 推荐(0) 编辑
摘要: 1 方法一,使用[::-1]: 2 3 s = 'python' 4 print(s[::-1]) 5 6 7 方法二,使用reverse()方法: 8 9 n = list(s) 10 n.reverse() 11 print(''.join(n)) 12 13 results: 14 15 nohtyp 16 nohtyp 阅读全文
posted @ 2018-01-11 18:08 jonm 阅读(446) 评论(0) 推荐(0) 编辑
摘要: 1 my_str = 'hello' 2 # for循环 3 for v in my_str: 4 print(v) 5 # while 配合迭代器实现字符串的遍历 6 ite = iter(my_str) 7 while True: 8 try: 9 each = next(ite) 10 except StopIteration: 1... 阅读全文
posted @ 2018-01-11 17:39 jonm 阅读(1866) 评论(0) 推荐(0) 编辑
摘要: 方法1 方法2 阅读全文
posted @ 2018-01-11 16:41 jonm 阅读(542) 评论(0) 推荐(0) 编辑
摘要: 三级菜单程序. 运行程序输出第一级菜单. 选择一级菜单某项,输出二级菜单,同理输出三级菜单. 退出时返回上一级菜单 menu = { '北京市': { '东城区': { 'aa', 'bb', }, '西城区': { 'cc', 'dd', }... 阅读全文
posted @ 2018-01-11 16:14 jonm 阅读(716) 评论(0) 推荐(0) 编辑
摘要: 购物车程序需求:. 启动程序后,让用户输入工资,然后打印商品列表. 允许用户根据商品编号购买商品. 用户选择商品后,检测余额是否够,够就直接扣款,不够就提醒.用户可一直购买商品,也可随时退出,退出时打印已购的商和余额 阅读全文
posted @ 2018-01-11 00:01 jonm 阅读(603) 评论(0) 推荐(0) 编辑