我从用户那里得到一个数字 (n)。 只是
n = int(input())
之后,我必须创建 n 个字符串并从用户那里获取它们的值。
i = 0;
while (i < n):
word = input() # so here is my problem:
# i don't know how to create n different strings
i += 1
如何创建n个字符串?
最佳答案
你需要使用一个列表,像这样:
n = int(input())
i = 0
words = []
while ( i < n ):
word = input()
words.append(word)
i += 1
此外,最好将此循环创建为 for 循环:
n = int(input())
words = []
for i in range(n):
words.append(input())
关于python - 在 Python 中创建 n 个字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39994332/