![](https://img-blog.csdnimg.cn/20201014180756918.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
python
_那年夏天
这个作者很懒,什么都没留下…
展开
-
json和pickle
json序列化 json picklepickle 只有python能够识别json 能被所有语言识别dumps与loads# dumps:用来序列化一个对象# dumps 可以指定一下参数# sort_keys:根据key来排序# indent:以2个空格缩进# ensure_ascii: 可以序列化中文#如何序列化 与反序列化import jsond={'k1':'aa', 'k2':'bb', 'k3':'cc'}#json序列化res = json.dumps原创 2021-03-18 14:46:14 · 53 阅读 · 0 评论 -
python文件操作
文章目录文件打开模式使用文件打开模式控制文件读写操作模式r :只读模式w : 只写模式a : 只追加模式控制文件读写内容模式t : 读写的内容都是字符串特点:只适用于文本文件必须指定encoding参数b : 读写的内容都是bytes类型特点:一定不要指定encoding参数使用r 模式:如果文件不存在则报错,文件存在则将指针跳到文件的开头with open('c.txt', 'rt', encoding='utf-8') as f: res = f.read()原创 2021-03-17 16:29:22 · 91 阅读 · 0 评论 -
python数据类型使用
数据类型数字类型 int float用来记录数字相关的数据类型# int 用来记录整数类型数据# 如:年龄、年份、人数age = 18year = 2020count = 20#float 用来记录带小数点的数据类型# 如:工资、身高、体重salary = 1800.29height = 180.3weight = 50.2#数字类型使用#数学运算>>> a = 1>>> b = 2>>> c = a +原创 2021-03-09 19:14:48 · 114 阅读 · 0 评论 -
python 模块
**time **import timeres = time.time() #时间戳,从1970年1月1日 00:00:00到当前时间的秒数print(res) #1612145065.0112846res = time.localtime() # 本地时区的结构化时间print(res) #time.struct_time(tm_year=2021, tm_mon=2, tm_mday=1, tm_hour=10, tm_min=8, tm_sec=24, tm_wday=0, tm原创 2021-02-01 11:40:05 · 74 阅读 · 0 评论 -
python 函数递归
递归就是自己调自己递归没调用一次都会申请内存空间,python为了限制无限调用占用内存空间,把递归内部做了层级限制直接调用def func(): print(11) func()func()# 报错# RecursionError: maximum recursion depth exceeded while calling a Python object# python 内部机制递归最大层数,默认值是1000# 可以通过 sys.getrecursionlim原创 2021-01-28 16:40:31 · 54 阅读 · 0 评论 -
python 生成式
l = [1, 3, 4, 5, 6, 7, 8, 9]new_l = []for i in l: if i > 4: new_l.append(i)print(new_l)# 相当于上边的代码# i 是条件成立的值,循环判断条件,条件成立的话就把值加到列表里边去new_l =[i for i in l if i > 4]print(new_l)...原创 2021-01-28 15:22:35 · 104 阅读 · 0 评论 -
python 三元表达式
x = 1y = 2if x > y: print(x)else: print(y)# 相当于上边的if判断# 条件成立的值放到左边, 条件不成立的值放到右边res = x if x > y else yprint(res)原创 2021-01-28 15:07:50 · 95 阅读 · 0 评论 -
python 装饰器
无参装饰器def outter(func): # func:调用方法是传入的index的方法名 # (*args, **kwargs)表示什么值都可以接收,这里接收的是元组 (11, 22, 33) def wrapper(*args, **kwargs): print("args>>>>>>>", *args) # args>>>>>>> 11 22 print(原创 2021-01-27 19:11:11 · 134 阅读 · 1 评论