打印字符串 n 次

5年以前  |  阅读数:455 次  |  编程语言:Python 

在不使用循环的情况下,要打印一个字符串 n 次是非常容易的,如下所示。

def repeat(string, n):
    return (string * n)

repeat('python', 3) # pythonpythonpython

Copyright© 2013-2020

All Rights Reserved 京ICP备2023019179号-8