摘要: #1、有个文件#2、打开文件#3、操作文件 读和写#4、关闭文件#只读模式,默认#写模式#追加模式 a+#w是会清空文件内容的,然后写f = open('user.txt','a+') #a+是追加模式f.seek(0)#移动文件指针,0代表从文件开头开始算起,1代表从当前位置开始算起,2代表从文件 阅读全文
posted @ 2018-08-29 23:01 白兰鸽05 阅读(94) 评论(0) 推荐(0) 编辑
摘要: #strippassword = ' 123 45 \n 678\n'print(password.strip())#strip()去掉字符串两边的空格和换行符password = '.jpg 123 45.jpg678\n.jpg'#strip()可以去掉两边指定的空格print(password 阅读全文
posted @ 2018-08-29 23:01 白兰鸽05 阅读(182) 评论(0) 推荐(0) 编辑
摘要: #简化stu1和stu2#list里面放字典#字典里面放list#字典嵌套多层取值stus ={ "test001":{ 'sex':'男', 'email':'abc@qq.com', 'addr':'北京', 'id':1, 'cars':['牧马人','911','野马','劳斯莱斯'] }, 阅读全文
posted @ 2018-08-29 22:59 白兰鸽05 阅读(143) 评论(0) 推荐(0) 编辑
摘要: #字典:k-v形式,有点,速度快,好取值,字典没有索引,list有索引,字典没有顺序#name,sex,shengao,age,email,addr,idstu1 = { 'name':'张三', 'sex':'男', 'shengao':'180', 'age':20, 'email':'abc@ 阅读全文
posted @ 2018-08-29 22:58 白兰鸽05 阅读(137) 评论(0) 推荐(0) 编辑
摘要: #切片,对list取值的一种方式#L = list(range(10))#l = list(range(1,11))l = ['a','b','c','d','e','f','g','h','i','j','k']print(l)print(l[0:3])#顾头不顾尾print(l[:3])#最前面 阅读全文
posted @ 2018-08-29 22:57 白兰鸽05 阅读(114) 评论(0) 推荐(0) 编辑
摘要: #元组tuple也是一个列表,和列表相似,区别是元组不能修改,所以元组只有两个方法mysql = ('123.9.23.23',3306,"root",'1234')#mysql[1]=3307print(mysql[1])mysql.index(3306)#找索引值mysql.count(3306 阅读全文
posted @ 2018-08-29 22:56 白兰鸽05 阅读(104) 评论(0) 推荐(0) 编辑
摘要: list1=[1,2]list2=[1,2,3,[4,56]]print(list2[3][1])list3=[1,2,3,4,['a','b','c','d',['一','二','三']]]#三维数组#多维数组nums=[1,2,3,4,['a','b','c','d','e',['一','二', 阅读全文
posted @ 2018-08-29 22:55 白兰鸽05 阅读(184) 评论(0) 推荐(0) 编辑