【KataDaily 20220105】String repeat(字符重复)

题目:

Description:
Write a function called repeatStr which repeats the given string string exactly n times.
repeatStr(6, "I") // "IIIIII"
repeatStr(5, "Hello") // "HelloHelloHelloHelloHello"

 

自答:

def repeat_str(repeat, string):
    return "".join([string for i in range(repeat)])

 

高赞回答:

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

 

 
posted @ 2022-01-05 22:18  bcaixl  阅读(15)  评论(0编辑  收藏  举报