第九章 内置模块

目录

第九章 内置模块

1.math模块

1.查看:

2.常用方法:

2.random模块

1.查看:

​2.例:

3.random(a,b)

4.random.sample(range(0,20),10)

3.os模块与os.path模块

1.作用

2.目录

3.os模块与操作系统的关系

4.路径

5.判断目录是否存在

6.创建目录

7.删除目录

8.文件或目录的重命名

9.获取文件信息

10.常见的方法汇总​编辑

11.os.path模块的常用方法​编辑

4.sys模块

1.作用

2.常见方法​编辑

3.例:

5.UUID模块

1.定义

2. Python提供UUID1、3、4、5个版本的UUID

6.时间日期模块

1.time模块:

2.datetime模块

3.calendar模块 — 日历

7.加密模块hashlib

第九章 内置模块

1.math模块

1.查看:

import math
​
print(dir(math))
​
结果:
['__doc__', '__loader__', '__name__', '__package__', '__spec__', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'ceil', 'comb', 'copysign', 'cos', 'cosh', 'degrees', 'dist', 'e', 'erf', 'erfc', 'exp', 'expm1', 'fabs', 'factorial', 'floor', 'fmod', 'frexp', 'fsum', 'gamma', 'gcd', 'hypot', 'inf', 'isclose', 'isfinite', 'isinf', 'isnan', 'isqrt', 'lcm', 'ldexp', 'lgamma', 'log', 'log10', 'log1p', 'log2', 'modf', 'nan', 'nextafter', 'perm', 'pi', 'pow', 'prod', 'radians', 'remainder', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'tau', 'trunc', 'ulp']

2.常用方法:

函数描述math.e发布会欧拉数math.inf返回正无穷大的浮点数math.nan返回浮点数math.pi返回圆周率math.tau返回数学常数

第九章 内置模块

第九章 内置模块

第九章 内置模块

2.random模块

1.查看:

import random
​
print(dir(random))
​
结果:
['BPF', 'LOG4', 'NV_MAGICCONST', 'RECIP_BPF', 'Random', 'SG_MAGICCONST', 'SystemRandom', 'TWOPI', '_Sequence', '_Set', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '_accumulate', '_acos', '_bisect', '_ceil', '_cos', '_e', '_exp', '_floor', '_inst', '_log', '_os', '_pi', '_random', '_repeat', '_sha512', '_sin', '_sqrt', '_test', '_test_generator', '_urandom', '_warn', 'betavariate', 'choice', 'choices', 'expovariate', 'gammavariate', 'gauss', 'getrandbits', 'getstate', 'lognormvariate', 'normalvariate', 'paretovariate', 'randbytes', 'randint', 'random', 'randrange', 'sample', 'seed', 'setstate', 'shuffle', 'triangular', 'uniform', 'vonmisesvariate', 'weibullvariate']

​2.例:

seed( )方法—改变随机数的生成器种子,可以调用时使用

import random
​
random.seed()
print('默认:', random.random())
print('默认:', random.random())
​
random.seed(10)
print('使用10作为种子数:', random.random())
print('使用10作为种子数:', random.random())
​
random.seed('hello', 2)
print('字符串:', random.random())
​
​
结果:
默认: 0.8228169155922092
默认: 0.36032589277619675
使用10作为种子数: 0.5714025946899135
使用10作为种子数: 0.4288890546751146
字符串: 0.3537754404730722

3.random(a,b)

返回随机一个整数N,满足a

Original: https://blog.csdn.net/qq_57289939/article/details/127811800
Author: White乄joker
Title: 第九章 内置模块

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/655816/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球