Python random number usage method, derivation and string, two-color ball applet instance, python Random Number
As follows:
# Use import random for random numbers # import randomrandom. randint () # random number 0 to 9i = random. sample (range (), 6) # output 6 random numbers, ranging from 1 to 34i. sort () # sorting method. The original array is changed during sorting, and no return value is sorted (I) # sorting function. The original array is not affected during sorting, print ('---------------- use the preceding random number to make a two-color ball ---------------------') sj = random. sample (range (1, 34), 6) print (sj, random. randint () # if multi-value judgment n = 4if n in (,): print ('values in THE tuples are ', n,') else: print ('there is no such value in the tuples ', n,') # Use the while loop to output the sum of 1dao100 and I = 0he = 0 while I <100: he = he + I + = 1 print (he) # list sets use Bubble Sorting from Avenue small sort li = [9, 5, 7, 3] for I in range (0, len (li): for j in range (0, len (li)-i-1 ): if li [j] <li [j + 1]: li [j], li [j + 1] = li [j + 1], li [j] print (li) # Use of strings (methods, and parameters) zf = ('My hometown is in Henan! ') Print (zf [4]) # output with subscript, with 4th prints (zf [4:]) # print (zf [2: 5]) # print (zf [] * 2) # output string x 2 times print (zf. index ('south') # output the specified subscript print (zf. replace (',' d', 1) # replace the string with only one print (zf. endswith ('south'), 5, 6) # print ('home' in zf) # Whether the character exists # list print ('--------------- list ------------------') lb = ['abc', '123'] print (lb. append ('200') # Add a single lb + = ['A', 'B'] # add multiple lb. remove ('A') # delete an o = lb. pop (0) # specify the subscript to output lb. insert (2, '20140901') # specify the subscript to modify lb. clear () # delete all print (lb) print ('-------- derivation --------') td = ['hi', 'Hello', 'word', 'python ', 'height', 'Wall', 'higint'] print ([s for s in td if s. startswith ('H')])
The above python random number usage method, derivation and string, two-color ball mini-program instance is all the content shared by xiaobian, I hope to give you a reference, but also hope you can support more.