经常使用的一些公共方法



    #随机生成字符串 def random_str(self, num): str = '' chars = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789-_' length = len(chars) - 1 for i in range(num): str +=chars[random.randint(0, length)] return str #随机生成数字字符串 def random_int(self, num): str = '' chars = '0123456789' length = len(chars) - 1 for i in range(num): str +=chars[random.randint(0, length)] return int(str) #随机生成数字字符串+字母字符串 def random_rid(self, num=15): str = '' chars = '0123456789' chars1 = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789' length = len(chars) - 1 length1 = len(chars1) - 1 for i in range(5): str +=chars[random.randint(0, length)] for i in range(num): str +=chars1[random.randint(0, length1)] return str

  记录经常使用的一些方法,不用每次都自己写

上一篇:压缩字符串 -- LeetCode -- 8.21


下一篇:【LeetCode每日一题】1160. 拼写单词