"Python" Learning note 4-random, string module

Source: Internet
Author: User
Tags shuffle

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

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.