python 基础 之 模组
# python 基础 之 模组
# 1. 调用 time 模块
import time print(time.ctime())
# 2. 当然如果确定只调用 time 模块里的 ctime() 函数,那么可以用 from import 直接导入 ctime() 函数。
from time import ctime print(ctime())
# 3. 直接导入 time 模块下的多个函数
from time import ctime, sleep
# 4. 导入 time 模块下的所有函数
from time import * print(ctime()) print("休息2秒") print(sleep(2)) print(ctime())
# 5.如果导入的函数与自己定义的函数重名,可以用 as 对导入的函数重命名
from time import sleep as sys_sleep def sleep(sec): print("this is i defined sleep()") sleep(1) print(sys_sleep())
浙公网安备 33010602011771号