-
random 模块
random.seed(a=None,version=2) 指定种子来初始化伪随机数生成器
random.randrange(start,stop,step)
random.randint(a,b) 类似上条
random.choice(list) list里面随机选取
random.choices(list,weights=None,*,cum_weights=None,k=1) 随机取k个
random.shuffle(list) 给list 打乱排序
random.sample(list,k)
random.random()
random.gauss()
random.expovariate()
-
time 模块
time.localtime()
time.struct_time(tm_year=2020, tm_mon=4, tm_mday=5, tm_hour=22, tm_min=52, tm_sec=11, tm_wday=6, tm_yday=96, tm_isdst=0)
time.asctime((2020,2,3,11,2,23,0,0,0))
'Mon Feb 3 11:02:23 2020'
time.ctime(1586098478.3352435)
'Sun Apr 5 22:54:38 2020'
time.time()
1586098478.3352435
time.gmtime(1586098478.3352435)
time.struct_time(tm_year=2020, tm_mon=4, tm_mday=5, tm_hour=14, tm_min=54, tm_sec=38, tm_wday=6, tm_yday=96, tm_isdst=0)
time.mktime((2020,2,3,11,23,23,0,0,0))
1580700203.0
time.sleep()
time.strftime(format )
time.strptime(str)
time.timezone
time.tzname
-
re 模块
正则表达式,Regular Expression
字符串查找匹配
p=re.compile('abc') # p 是个 sre pattern对象 <class 're.Pattern'>
p.search('www.abc.com') # 返回 <class 're.Match'> 对象
re.search('abc','www.abc.com') #从中间找<re.Match object; span=(4, 7), match='abc'> 属性 span() 和 group()
re.match('abc','abc.com') # 从头开始找 <re.Match object; span=(0, 3), match='abc'> 属性 span() 和 group()
m=re.findall('abc','abc.com.abc') #返回['abc', 'abc']
网友评论