Python Learning Note 5--random

Source: Internet
Author: User

One, the random module

Import Random,stringprint (Random.randint (1,199)) #1-199 randomly take an integer print (string.digits) #所有的数字0 -9print (string.ascii_ lowercase) #所有的小写字母print (string.ascii_uppercase) #所有的大写字母print (string.ascii_letters) #所有的小写字母 + all uppercase letters print ( string.punctuation)  #所有的特殊字符s = Random.choice ([' Ybq ', ' mpp ', ' zhx ', ' DF ']) #随机取一个元素s = Random.choice () #随机取一个元素res = Random.sample (string.digits,3) #随机取N个元素print (". Join (res)) res = Random.uniform (1,9) #取随机小数?? Print (RES) print (round (res,2)) # retains several decimals, if after rounding, the last decimal number is 0, then the print (Random.random ())) #取0-1 random fractional s = [' A ', ' B ', ' C ', ' d ', ' E ']random.shuffle (s) #洗牌, scrambled in order, can only pass Listprint (s)

Python Learning Note 5--random

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.