Generate Random Verification Code instances
Import Randoma=[]c="' forIinchRange6): ifi = = Random.randrange (1,4): A.append (str (Random.randint (1,9))) Else: Temp= Random.randint ( $, -) a.append (Chr (temp)) Print ab="".Join(a) print B forIinchA:c+=str (i) Print C
Output to
[' D ', ' J ', ' A ', ' 5 ', ' B ', ' P '] dja5bpdja5bp
——————— Knowledge Extension
1. chr (i),英文说明: returns the ASCII character corresponding to the integer i. Contrary to the Ord () effect.
2. Character stitching method comparison. The following are examples of time-consuming comparisons:
Import Cstringioimport Stringioimport TimeValues=[]items= ['1,2,31,2,31,2,31,2,3'] *10000000#print itemsst=float( Time. Time()) forIinchItems:values.append (i) News="'.Join(values) print len (news) Print'list Append cost time:%s'%(float( Time. Time()) -St) Strio=Cstringio.stringio () St=float( Time. Time()) forJinchItems:strio.Write(j) Print Len (Strio.getvalue ()) Print'Cstringio cost time:%s'%(float( Time. Time()) -St) Strio=Stringio.stringio () St=float( Time. Time()) forJinchItems:strio.Write(j) Print Len (Strio.getvalue ()) Print'Stringio cost time:%s'%(float( Time. Time())-ST)
Generate Random Verification code