【Python】新建自定义个数的自定义长度名字
1 # -*- coding:utf-8 -*- 2 import random 3 def CreateRandomName(number,length): 4 """ 5 :param number: 执行次数 6 :param length: 名字的长度 7 :return: 8 9 """ 10 list = [] 11 for i in range(number): 12 for j in range(length): 13 list.append(str(random.randint(1,5))) 14 print "Autotest" + ''.join(list) 15 del list[:]16 17 >>>CreateRandomName(5,4) 18 19 C:\Python27\python.exe "E:/Project/exercise/test.py" 20 Autotest1522 21 Autotest5523 22 Autotest5415 23 Autotest1543 24 Autotest1314 25 26 Process finished with exit code 0
在第15行的时候,如果不清空列表的话,会导致列表里面数据一直呈现增涨的态势,跟预期的不一样