设为首页 加入收藏

TOP

Python初步了解装饰器(二)
2023-09-09 10:25:28 】 浏览:143
Tags:Python 步了解
器的语法糖
方案九
import time
def  ouct(func):
    # func=inside
    def worap(*args,**kwargs):
        stm_time=time.time()
        res=func(*args,**kwargs)
        end_time=time.time()
        print(end_time - stm_time)
        return res
    return worap
@ouct
def inside(group,s):

    print('欢迎来到英雄联盟')
    print(f'你所在的是{group}方阵营')

    print(f'敌军还要{s}秒到达战场')
    time.sleep(s)
    print('全军出击')
@ouct
def recharn(num):
    for i in range(num,101):
        time.sleep(0.05)
        print(f'\r当前电量{"‖"*i}{i}%',end='')
    print('电量已充满。')
recharn(20)
inside('红色',10)

装饰器的固定模块

def oute(funs):
    def waropper(*arges,**kwargs):
        res=funs(*arges,**kwargs)
        return res
    return waropper


# 时间差模块
import time
def oute_time(funs):
    def waropper(*arges,**kwargs):
        cmd_time=time.time()
        res=funs(*arges,**kwargs)
        out_time=time.time()
        print(out_time-cmd_time)
        return res
    return waropper
@oute_time
def home():
    time.sleep(2)
    print('estdsfs')
首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇深入理解 Python and 逻辑运算符(.. 下一篇使用python311+pycharm社区版+MyS..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目