摘要: 一.json转化成字典: product.json文件:将该文件内容转换成python中字典,方法如下: 方法一:使用.loads(),先读后转换 import json #导入json, 注:json串是一个字符串 f = open('product.json',encoding = 'utf-8 阅读全文
posted @ 2018-04-17 15:36 我已不爱凯蒂 阅读(385) 评论(0) 推荐(0) 编辑
摘要: 内置函数 python自带的一些函数,直接拿过来能用的 id() #看内存地址 type() #看数据类型 print() #打印 input() #输入 list() #转list set()# 转集合 str()#转字符串 dict()#转字典 int()#转int float()#转float 阅读全文
posted @ 2018-04-17 13:59 我已不爱凯蒂 阅读(123) 评论(0) 推荐(0) 编辑
摘要: import random,string# print(string.printable) #代表 数字+字母+特殊字符## print(random.randint(1,10)) #随机取整数# print(round(random.uniform(1,99),2))#随机小数# print(ra 阅读全文
posted @ 2018-04-17 13:58 我已不爱凯蒂 阅读(113) 评论(0) 推荐(0) 编辑
摘要: def say(): #函数名 print('hello')#函数体#函数不调用是不会被执行的# say() #调用函数#函数的参数def calc(a,b): #形参, 形式参数 #位置参数,必填参数 res = a * b print('%s * %s = %s'%(a,b,res))# cal 阅读全文
posted @ 2018-04-17 13:53 我已不爱凯蒂 阅读(167) 评论(0) 推荐(0) 编辑
摘要: f = open('user','a+') f.write('abcde') #write只能写字符串 f.writelines(['444','rrrr','uuu']) #writelines会帮我们自动循环一次,即可以写列表 阅读全文
posted @ 2018-04-17 13:47 我已不爱凯蒂 阅读(322) 评论(2) 推荐(0) 编辑
摘要: 文档username.txt 将文件中密码123456改成67890: 方法一:(简单粗暴) 1.打开文件 2.读出数据 3.修改数据 4.清空原来文件,将新的内容写进去 f = open('username','a+') f.seek(0) all_str = f.read() new_str = 阅读全文
posted @ 2018-04-17 13:34 我已不爱凯蒂 阅读(153) 评论(0) 推荐(0) 编辑