简体   繁体   中英

How do you make a string repeat itself in python

How do I make a string repeat itself for example:

instead of writing print ('---------------------------') how do I make it something like print ('-') * 60 ?

You were so close:

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

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

You were very close - it's

print "-" * 60

In Python 2, in Python 3, it's

print ("-" * 60)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM