python - PySchools - 主题 1 问题 7

标签 python string

我在 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'

关于python - PySchools - 主题 1 问题 7,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5866933/

相关文章:

python - 在 Python 中提取文件名的后缀

c++ - << 未找到运算符和无法识别的转义序列

.net - 在多行文本框中格式化字符串

python 在一行中将列表项转换为 unicode

python - 从 NLTK 中的 Text.similar() 和 ContextIndex.similar_words() 生成的单词按频率排序?

c - fgets 读取的最大尺寸

Java:字符串:没有给出好的结果

r - 选择具有R中最长字符串的列

python:打印带有时区信息的时间和日期

python - 用Python NDB有效实现一对多关系