目录
4.random.sample(range(0,20),10)
2. Python提供UUID1、3、4、5个版本的UUID
第九章 内置模块
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/
转载文章受原作者版权保护。转载请注明原作者出处!