简体   繁体   English

你如何使字符串在python中重复

[英]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 ? 而不是写print ('---------------------------')我该如何使其类似于print ('-') * 60

You were so close: 你是如此亲密:

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

You need to multiply the str value, not the return value of the print() function. 您需要乘以str值, 而不是 print()函数的返回值。

You were very close - it's 你离我很近-

print "-" * 60

In Python 2, in Python 3, it's 在Python 2中,在Python 3中,

print ("-" * 60)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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