【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