math库:

>>> import math
>>> dir(math)
['__doc__', '__loader__', '__name__', '__package__', '__spec__', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'ceil', 'copysign', 'cos', 'cosh', 'degrees', 'e', 'erf', 'erfc', 'exp', 'expm1', 'fabs', 'factorial', 'floor', 'fmod', 'frexp', 'fsum', 'gamma', 'gcd', 'hypot', 'inf', 'isclose', 'isfinite', 'isinf', 'isnan', 'ldexp', 'lgamma', 'log', 'log10', 'log1p', 'log2', 'modf', 'nan', 'pi', 'pow', 'radians', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'tau', 'trunc']
>>> math.pi
3.141592653589793
>>> math.e
2.718281828459045
>>> help(math.ceil)
Help on built-in function ceil in module math: ceil(...)
ceil(x) Return the ceiling of x as an Integral.
This is the smallest integer >= x. >>> math.ceil(3.6)
4
>>> math.floor(3.6)
3
>>> math.pow(2,3)
8.0
>>> math.sqrt(4)
2.0
>>> math.degrees(3.14)
179.9087476710785
>>> math.radians(180)
3.141592653589793

  os库:

import os
>>> os.getcwd()
'C:\\Users\\Administrator\\AppData\\Local\\Programs\\Python\\Python36-32'
>>> path='e:\\test'
>>> os.chdir(path)
>>> os.getcwd()
'e:\\test'
>>> os.rename('test.txt','test111.txt')
>>> os.remove('test111.txt')
>>>

  

random库:

>>> import random
>>> random.choice(['C++','Java','Python'])
'Java'
>>> random.randint(1,100)
57
>>> random.randrange(0,10,2)
8
>>> random.random()
0.7906454183842933
>>> random.uniform(5,10)
7.753307224388041
>>> random.sample(range(100),10)
[91, 15, 67, 38, 55, 72, 62, 97, 51, 77]
>>> nums=[1001,1002,1003,1004,1005]
>>> random.shuffle(nums)
>>> nums
[1002, 1004, 1005, 1001, 1003]

  datetime库:

import datetime
>>> dir(datetime)
['MAXYEAR', 'MINYEAR', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'date', 'datetime', 'datetime_CAPI', 'time', 'timedelta', 'timezone', 'tzinfo']
>>> from datetime import date
>>> date.today()
datetime.date(2018, 3, 7)
>>> from datetime import time
>>> tm=time(23,20,35)
>>> print(tm)
23:20:35
>>> from datetime import datetime
>>> dt=datetime.now()
>>> dt
datetime.datetime(2018, 3, 7, 15, 1, 7, 13107)
>>> print(dt.strftime('%a,%b %d %Y %H:%M'))
Wed,Mar 07 2018 15:01
>>> dt=datetime(2017,6,6,23,29)
>>> print(dt)
2017-06-06 23:29:00
ts=dt.timestamp()
>>> ts
1496762940.0
print(datetime.fromtimestamp(ts))

  

Python常用标准库函数的更多相关文章

  1. C语言中最常用标准库函数

    标准头文件包括: <asset.h>      <ctype.h>       <errno.h>       <float.h> <limits ...

  2. python常用标准库

    -------------------系统内建函数------------------- 1.字符串     str='这是一个字符串数据测试数据'对应     str[0]:获取str字符串中下标为 ...

  3. Python常用标准库(pickle序列化和JSON序列化)

    常用的标准库 序列化模块 import pickle 序列化和反序列化 把不能直接存储的数据变得可存储,这个过程叫做序列化.把文件中的数据拿出来,回复称原来的数据类型,这个过程叫做反序列化. 在文件中 ...

  4. python常用标准库(时间模块 time和datetime)

    常用的标准库 time时间模块 import time time -- 获取本地时间戳 时间戳又被称之为是Unix时间戳,原本是在Unix系统中的计时工具. 它的含义是从1970年1月1日(UTC/G ...

  5. python常用标准库(os系统模块、shutil文件操作模块)

    常用的标准库 系统模块 import os 系统模块用于对系统进行操作. 常用方法 os模块的常用方法有数十种之多,本文中只选出最常用的几种,其余的还有权限操作.文件的删除创建等详细资料可以参考官方文 ...

  6. python常用标准库(压缩包模块zipfile和tarfile)

    常用的标准库 在我们常用的系统windows和Linux系统中有很多支持的压缩包格式,包括但不限于以下种类:rar.zip.tar,以下的标准库的作用就是用于压缩解压缩其中一些格式的压缩包. zip格 ...

  7. python 常用标准库

    标准库和第三方库第一手资料: 在线: 官方文档(https://docs.python.org/) 离线:交互式解释器(dir().help()函数),IPython(tab键提示.?.??) 一.  ...

  8. python常用标准库(math数学模块和random随机模块)

    常用的标准库 数学模块 import math ceil -- 上取整 对一个数向上取整(进一法),取相邻最近的两个整数的最大值. import math res = math.ceil(4.1) p ...

  9. Python常用标准库之datetime、random、hashlib、itertools

    库:具有相关功能模块的集合 import sys.builtin_module_names #返回内建模块的名字modules 查看所有可用模块的名字 1.1.1获取当前日期和时间 from date ...

随机推荐

  1. Docker 两键创建 ZeroTier moon 节点

    一条命令创建 ZeroTier moon 节点: $ docker run --name zerotier-moon -d -p 9993:9993 -p 9993:9993/udp seedgou/ ...

  2. SQL Server 2019 中标量用户定义函数性能的改进

    在SQL Server中,我们通常使用用户定义的函数来编写SQL查询.UDF接受参数并将结果作为输出返回.我们可以在编程代码中使用这些UDF,并且可以快速编写查询.我们可以独立于任何其他编程代码来修改 ...

  3. 解决非controller使用@Autowired注解注入为null问题

    在SpringMVC框架中,我们经常要使用@Autowired注解注入Service或者Mapper接口,我们也知道,在controller层中注入service接口,在service层中注入其它的s ...

  4. 2019牛客暑期多校训练营(第二场)H Second Large Rectangle

    示例一: 输入  : 1 2 01 输出: 0 示例二: 输入  : 1 3 101 输出: 1 示例三(自己自测找错误用的): 输入  : 6 610011111101111111111111111 ...

  5. Linux基础(10)AIO项目设计与POSIX文件操作和目录管理

    实现fast-cp :拷贝文件到目标对象 Linux的七种文件类型 :https://blog.csdn.net/linkvivi/article/details/79834143 ls -al :h ...

  6. vs2017- C语言- winsocket- 链接错误 LNK2019

    错误介绍 操作系统:windows10 IDE:vs2017 语言:C语言 项目内容简介:编写一个双人网络海战棋对战游戏 错误类型:链接错误 LNK2019 解决方案:程序需要用到ws2_32.lib ...

  7. EasyExcel写文件

    公共部分 HttpServletResponse // 需要处理response HttpServletResponse response; response.reset(); response.se ...

  8. yii框架中的各种小问题

    1.默认路径的修改 2.分页的做法

  9. WPF 使用 AppBar 将窗口停靠在桌面上,让其他程序不占用此窗口的空间(附我封装的附加属性)

    原文:WPF 使用 AppBar 将窗口停靠在桌面上,让其他程序不占用此窗口的空间(附我封装的附加属性) 本文介绍如何使用 Windows 的 AppBar 相关 API 实现固定停靠在桌面上的特殊窗 ...

  10. AspNetCore MVC页面数据提交验证

    2019/05/14,AspNetCore 2.2.0 摘要:AspNetCore MVC使用数据注释配合jquery.validate提交页面进行前端加后端的数据验证 主要用到了jquery.val ...