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 Autotest152221 Autotest552322 Autotest541523 Autotest154324 Autotest131425 26 Process finished with exit code 0
在第15行的时候,如果不清空列表的话,会导致列表里面数据一直呈现增涨的态势,跟预期的不一样