Day11:The time and random module

'''
# 1::module(.py): 1;excute related files 2;quote variables
# 2::package
# import ...
# import module1[,module2,[module3]]...
# from ...import ...
# from ...import *
# from web.web1.web2 import cal
# from web.web1.web2.cal import add
# print(cal.add())

# use: if __name__ == '__mian__' to distingwish 'bin' file
#*********time module:**************
# 1:*********time point:
import time
# print(time.time())
# 1578806899.032914 (the seconds record from 1970)
# 2:*********structual time:
# print(time.localtime())
# the local time
# print(time.gmtime(14727782898))
# can add the parameter in it
# the international time
# t = time.localtime()
# print(t.tm_year)
# print(t.tm_wday)
# 3:*********transfer the structual time into point time:
# print(time.mktime(time.localtime()))
# 4:*********transfer the structual time into string time:
# print(time.strftime('%Y-%m-%d %X',time.localtime()))
# notice the capital and lowercase
# 5:*********transfer the string time into  structual time:
print(time.strptime('2020:01:12:16:50:35','%Y:%m:%d:%X'))
# 6:*********get the time directly:
print(time.asctime())
print(time.ctime())
# datetime have a better formation
import datetime
print(datetime.datetime.now())
#**************be care not to use the same name: Cause the finding path is finding the current package first.(eg:re.py(in python); re.py(in current package))
#*********random module:**************
import random
ret = random.random()
# float
ret = random.randint(1,3)
# [1,3]
ret = random.randrange(1,3)
# [1,3)
ret = random.choice([11,22,33,44])
ret = random.sample([11,22,33,44],3)
print(ret)
import random
ret = [11,22,33,44,55]
random.shuffle(ret)
print(ret)
'''
# a example:
import random
def v_code():
    ret = ''
    for i in range(5):
        num = random.randint(0,9)
        alf = chr(random.randint(65,122))
        s = str(random.choice([num,alf]))
        ret += s
    return ret
print(v_code())
        

猜你喜欢

转载自www.cnblogs.com/zxver/p/12184510.html