跳转至

使用技巧#

函数只支持指定名称参数#

参数定义最前面先放一个 * 后面再定义参数,函数调用时就必须指定参数名传参

def myfun(*, par1:str, par2:str):
    pass

向下取整#

1
2
3
4
5
import math

math.floor(5 / 2)  # 2

5 // 2             # 2

获取文件大小#

1
2
3
import os

os.path.getsize("file")  # 单位是字节