Python3 time module & amp; datetime module & amp; random module, python3time Module

Source: Internet
Author: User

Python3 time module & datetime module & random module, python3time Module

1 '''2 time module 3 '''4 5 # import time 6 # print (help (time) # help () help 7 # print (time. time () # number of seconds (timestamp) from January 1, 1970-key 8 # time. sleep (3) # CPU does not work, blocking-key 9 # print (time. clock () # computing CPU time 10 #11 # structured (in the form of tuples) 12 # print (time. gmtime () # Greenwich Mean time, Standard time -- Key 13 # time. struct_time (tm_year = 2017, tm_mon = 10, tm_mday = 18, tm_hour = 1, tm_min = 56, tm_sec = 47, tm_wday = 2, tm_yday = 291, tm_isdst = 0) 14 # print (time. localtime () # local time -- emphasis 15 # a1 = time. localtime () 16 # print (time. strftime ('% Y-% m-% d % H: % M: % s', a1) # customize the time display style -- emphasis 17 # print (time. strptime ('2017-09-08 10:21:10 ',' % Y-% m-% d % H: % M: % s') # convert to structured time, the format before and after must be one-to-one, and each city must be 18 # key 19 # print (time. ctime () # current time (the format cannot be dynamic). The parameter is blank by default. After adding the parameter, convert the parameter to the time, from January 1, 1970 to 20 # print (time. mktime (time. localtime () # convert to timestamp 21 22 ''' 23 datetime module 24''' 25 # import datetime26 # print (datetime. datetime. now () # display current time 27 28 29 30 31 ''' 32 random module 33''' 34 # import random35 #36 # print (random. random () # number of random builds, random () -- default range: 0-137 # print (random. randint (838) # range: 1-# print (random. choice ('hello') # randomly select 39 # print (random. choice ([123, 'asd ', [1, 2]) # randomly selected element 40 # print (random. sample ([123, 'asd '],) # TypeError: sample () takes 3 positional arguments but 4 were given41 # print (random. sample ([123, 'asd '], 1) # correct 42 # print (random. randrange (443) # range value less than 5, range 1-147 #44 #45 # verification code function 46 # version -- # def rand_code (): 48 # code = ''49 #50 # for I in range (5): 51 # if I = random. randint (0, 4): 52 # add = random. randrange (10) 53 # else: 54 # add = chr (random. randrange (260) 55 # code + = str (add) 56 # print (code) 57 # rand_code () 58 #59 # version -- # def fun1 (): 61 # code = ''62 # for I in range (5): 63 # add = random. choice ([random. randrange (10), chr (random. randrange (65,91)]) 64 # code + = str (add) 65 # print (code) 66 # fun1 ()

 

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.