re 模块简单运用
import random from random import randint, choice, sample # for i in range(20): # test = random.randint(1, 10)#1-10之间的整数,包括1和10 # # test1=random.random()#0到1 之间的小数 # # test2=random.uniform(1,5)#从开始到结束之间的数,包括整数和小数 # print('我是test',test) # # print('我是test2',test2) # # # print('我是test1',test1) # def rand_int(start,stop): # ''' # # :param start: 开始数字 # :param stop: 结束或停止数字 # :return: 返回值 # ''' # a=random.random()#(0-1)之间的随机数 # print(a) # print(a*(stop-start)) # return round(a*(stop-start)+start) # # print(rand_int(1,10)) # # def rand_str(l=4,t=0): # ''' # # :param l: 指定参数与值 # :param t: 指定参数与值 # :return: # ''' # s = '' # if t == 0: # 纯数字 # for i in range(l): # # s = s + chr(randint(ord('0'), ord('9'))) # s = s + str(randint(0, 9)) # print(s) # elif t == 1: # 纯字母 # base_str = 'abcdefghijklmnopqrstuvwxyz' # # s = ''.join(sample(base_str, l))#sample(base_str, l)从字符串中随机选出l个元素 # # y=choice(base_str)#choice(base_str)字符串中随机选择一个 # # print(y) # # s = ''.join( y for i in range(l))#误区这里面的y与choice(base_str)并不等价,只是把值赋给了y # s = ''.join( choice(base_str) for i in range(l)) # else: # 数字字母混合 # pass # return s # # # print(rand_str(4,0))#指定的参数只可以改变,也可以把指定参数l,t去除