1 random number
1 Importrandom,string2 Print(Random.random ())#Random floating-point number, default 0-1, cannot specify range3 Print(Random.randint (1,20))#random integers4 Print(Random.randrange (1,20))#randomly produces a range5 Print(Random.choice ('X23serw4'))#randomly take an element6 Print(Random.sample (string.digits,2))#randomly fetching several elements from a sequence7 Print(Random.uniform (1,9))#Random floating point number, you can specify the range8 Print(Round (Random.uniform (1,9), 5))#Random floating point number, you can specify the range #round保留几位小数9x = [1,2,3,4,6,7]TenRandom.shuffle (x)#Shuffle, scramble order, will change the value of the original list, itself no return value One Print(x) A Print(string.ascii_letters+string.digits)#all the numbers and letters
2. String takes uppercase and lowercase letters special characters
1 # 0-9 all the numbers 2 # all uppercase and lowercase letters 3 # All lowercase letters 4 # All uppercase Letters 5 # all the special characters 6 Print (s)
"Python" Learning note 4-random, string module