python time模块和random 模块

import os
import datetime

# 年-月-日 时:分:秒
nowTime=datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
# 年-月-日
dayTime = datetime.datetime.now().strftime('%Y-%m-%d')
# 时:分:秒
hourTime = datetime.datetime.now().strftime('%H:%M:%S')
print(nowTime + '\n' + dayTime + '\n' + hourTime)

mobile = 176
pwd = os.getcwd() + '\\' + dayTime + '\\' + str(mobile)
print(pwd)
'''
D:\py\venv\Scripts\python.exe D:/pycode/21/day21_lesson/test.py
2018-10-26 16:29:14
2018-10-26
16:29:14
D:\pycode\21\day21_lesson\2018-10-26\176
'''
#时间戳  #计算
# print(time.time())    #1481321748.481654秒

#结构化时间---当地时间
# print(time.localtime(1531242343))
# t=time.localtime()
# print(t.tm_year)
# print(t.tm_wday)
# #-----#结构化时间---UTC
# print(time.gmtime())

#-----将结构化时间转换成时间戳

# print(time.mktime(time.localtime()))
#------将结构化时间转成字符串时间strftime
#print(time.strftime("%Y---%m-%d %X",time.localtime()))
#------将字符串时间转成结构化时间strptime
#print(time.strptime("2016:12:24:17:50:36","%Y:%m:%d:%X"))

# print(time.asctime())
# print(time.ctime())


# import datetime
# print(datetime.datetime.now())

随机模块

import random

# ret=random.random()
# ret=random.randint(1,3)
# ret=random.randrange(1,3)
# ret=random.choice([11,22,33,44,55])
# ret=random.sample([11,22,33,44,55],2)
# ret=random.uniform(1,4)
#
# print(ret)
# ret=[1,2,3,4,5]
# random.shuffle(ret)
# print(ret)

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())

 

你可能感兴趣的:(python)