How do you make a string repeat itself in python

前端 未结 2 1182
孤城傲影
孤城傲影 2021-01-26 03:23

How do I make a string repeat itself for example:

instead of writing print (\'---------------------------\') how do I make it something like print (\'

相关标签:
2条回答
  • 2021-01-26 03:48

    You were very close - it's

    print "-" * 60
    

    In Python 2, in Python 3, it's

    print ("-" * 60)
    
    0 讨论(0)
  • 2021-01-26 04:08

    You were so close:

    >>> print('-' * 60)
    ------------------------------------------------------------
    

    You need to multiply the str value, not the return value of the print() function.

    0 讨论(0)
提交回复
热议问题