我在 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 =
最佳答案
您可以将字符串乘以整数,以便多次重复该字符串。
>>> 'abc' * 2
'abcabc'
关于python - PySchools - 主题 1 问题 7,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5866933/