十三.Python模块

Python模块

#20 模块
#分类:
#   内置函数模块
#   第三方函数模块
#   应用自定义函数模块

#模块的使用

#导入模块
import  time  #导入time模块
from time import localtime  #从time模块中导入localtime()函数
print(localtime())

#获取当前文件夹下的自定义模块(.py文件)
import cale
print(cale.add(4,6))

from cale import add
print(add(6,30))

#获取子文件夹下的自定义模块(.py文件)

from abc11 import cale  as v     #导入abc11文件夹下的cale模块作为v
print(v.add(60,60))               #调用cale模块下的add函数
import abc11.cale as g           #导入abc11文件夹下的cale模块作为v
print(g.add(1,7))
from  abc11 import test  as t    #获取abc python包下__init__模块下的test函数
t()                               #执行test函数

#time模块及函数    Python内置函数
import time

#时间的种类
#时间戳          用于时间运算
#结构化时间      #字典时间
#字符串时间      用于显示的时间

#time       #时间戳
print("当前时间戳 %s"%(time.time()))
#localtime  #结构化时间
print(time.localtime())
#gmtime     #格林尼治结构化时间
print(time.gmtime())
#mktime     #将结构化时间转换为时间戳
print(time.mktime(time.localtime()))
#asctime    #将结构化时间转换为字符串时间
print(time.asctime(time.localtime()))
#ctime      #将时间戳转换为字符串时间
print(time.ctime(time.time()))
#strftime   将结构化时间转换为字符串时间
# %Y 年
# %m 月
# %d 日
# %X 时分秒
print(time.strftime("%Y-%m-%d %X",time.localtime()))

#strptime   将字符串时间转换为结构化时间
print(time.strptime("2106-10-15 12:10:39","%Y-%m-%d %X"))

#sleep 使程序暂停多少秒
time.sleep(3)   #程序暂停2秒

#clock  返回程序运行的耗时
print(time.clock())


# random 随机模块
import random

#random()  0-1之间的随机浮点数
print(random.random())
#randomint()  #随机两个参数之间的随机整数
print(random.randint(10,20))
#randrange()  #随机两个参数之间的随机整数
print(random.randrange(10.0,20.0))
#choice()     在列表参数里随机选择一个
print(random.choice([11,15]))
#shuffle()  将列表里的参数打乱顺序
li=[1,2,3,4,5,6,7,8,9]
random.shuffle(li)
print(li)
#uniform()  获取参数之间的随机浮点数
res=random.uniform(15,60)
print(res)



猜你喜欢

转载自blog.csdn.net/qq_39663113/article/details/85223604