我在PySchools.com上经历了一些关于Python的实践,被困在这里。我敢肯定这是一个简单的任务。任何人?

您可以使用len(x)函数找出字符串中的字符数。

例子

>>> greetings = "Hello World"
>>> len(greetings) # get the length of string
11
>>> greetings[0] # get the 1st character
'H'


问题在下面:

greeting = "Hello Google!"
# number of characters stored in the variable greeting
number_of_char = len(greeting)

# repeat the greetings based on the number of character in 'greeting'
greetings =


http://www.pyschools.com/quiz/view_question/s1-q7

最佳答案

您可以将字符串乘以整数,以便多次重复该字符串。

>>> 'abc' * 2
'abcabc'

10-04 12:29