Python 面试题

请完善装饰器 repeat 函数代码,实现输入任意正整数,打印 n 次 hello

def repeat(num: int):
    pass


@repeat(n)
def print_hello():
    print("hello")
点我看答案
def repeat(num: int):
    def new(old):
        for i in range(num - 1):
            old()
        return old

    return new


@repeat(n)
def print_hello():
    print("hello")
© 2022 刘士. All rights reserved.

结果匹配 ""

    没有匹配的结果 ""