美文网首页
9.Python-Python常用标准库函数

9.Python-Python常用标准库函数

作者: Yuri7 | 来源:发表于2019-06-17 16:32 被阅读0次

    Python常用标准库函数

    dir(functionname)查看模块中包含的函数名字

    math

    操作 detail 操作 detail
    math.ceil(num) 向上取整 math.floor(num) 向下取整
    math.pow(num1,num2) 求次方 math.sqrt(num) 开方
    math.degrees(degree) 弧度转角度 math.radians(radian) 角度转弧度

    </font size=2>

    os

    操作 detail 操作 detail
    os.getcwd() 获得路径 os.chdir(path) 更改地址
    os.rename(old,new) 改名字 os.remove(filename) 移除文件

    random

    操作 detail
    random.choice(l) 从序列中获取随机值
    random.randint(start,stop) 从区间随机生成整数
    random.randrange(start, stop, step) 从range中获取一个随机整数
    random.random() 生成0-1.0(不包含1.0)的一个随机数:
    random.uniform(start, stop) 生成随机浮点数
    random.simple(range(),n) 从range中随机生成一个有n个数的列表
    random.shuffle(l) 将列表随机打乱

    datatime

    from datatime import datatime, date, time

    操作 detail
    data.today() 获得今天时间
    time(hour,min, sec) 创建时间
    datetime(year, month, day, hour, min, sec) 创建日期时间
    dt=datetime.now() 查看当前日期和时间
    dt.strftime('%a, %b %d %Y %H:%M') 更换格式
    ts=dt.timestamp() 时间戳转换时间
    datetiime.fromtimestamp(ts) 时间转换到时间戳

    相关文章

      网友评论

          本文标题:9.Python-Python常用标准库函数

          本文链接:https://www.haomeiwen.com/subject/fctzfctx.html