Display string multiple times

前端 未结 2 1425
别跟我提以往
别跟我提以往 2020-11-29 03:19

I want to print a character or string like \'-\' n number of times.

Can I do it without using a loop?.. Is there a function like

print(\'-\',3)
         


        
2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-29 03:53

    The accepted answer is short and sweet, but here is an alternate syntax allowing to provide a separator in Python 3.x.

    print(*3*('-',), sep='_')
    

提交回复
热议问题