Python 我想从用户那里得到一个字符串列表,我应该如何得到它?
我想从用户那里获得一系列字符串,并将其放入列表中,然后打印出来 我还想在我完成时关闭列表并打印它Python 我想从用户那里得到一个字符串列表,我应该如何得到它?,python,arrays,lis,Python,Arrays,Lis,我想从用户那里获得一系列字符串,并将其放入列表中,然后打印出来 我还想在我完成时关闭列表并打印它 list = [] for i in list: list[a]=input('the name of stings:') list.append(list[a]) a += print(list) 试试这个: list_ = [] not_done = True while not_done: inp = input('name of string :
list = []
for i in list:
list[a]=input('the name of stings:')
list.append(list[a])
a +=
print(list)
试试这个:
list_ = []
not_done = True
while not_done:
inp = input('name of string : ')
if inp.lower() != 'done': # Put any string in stead of 'done' by which you intend to not take any more input
list_.append(inp)
else:
break
print(list_)
输出:
name of string : sd
name of string : se
name of string : gf
name of string : yh
name of string : done
['sd', 'se', 'gf', 'yh']
试试这个:
list_ = []
not_done = True
while not_done:
inp = input('name of string : ')
if inp.lower() != 'done': # Put any string in stead of 'done' by which you intend to not take any more input
list_.append(inp)
else:
break
print(list_)
输出:
name of string : sd
name of string : se
name of string : gf
name of string : yh
name of string : done
['sd', 'se', 'gf', 'yh']
您可以这样做:
n = int(input())
my_list = list()
for i in range(n):
my_str = input('Enter string ')
my_list.append(my_str)
print('You entered', my_str)
print(my_list)
以下是示例(第一行获取数字,表示您希望获取输入的次数):
您可以这样做:
n = int(input())
my_list = list()
for i in range(n):
my_str = input('Enter string ')
my_list.append(my_str)
print('You entered', my_str)
print(my_list)
以下是示例(第一行获取数字,表示您希望获取输入的次数):
示例如下所示:
input_list = []
while True:
your_input = input('Your input : ')
if your_input.upper() == "DONE":
break
input_list.append("%s" % your_input )
print("%s" % input_list)
输出:
>>> python3 test.py
Your input : a
Your input : b
Your input : c
Your input : d
Your input : dOnE
['a', 'b', 'c', 'd']
示例如下所示:
input_list = []
while True:
your_input = input('Your input : ')
if your_input.upper() == "DONE":
break
input_list.append("%s" % your_input )
print("%s" % input_list)
输出:
>>> python3 test.py
Your input : a
Your input : b
Your input : c
Your input : d
Your input : dOnE
['a', 'b', 'c', 'd']
您打算输入多少次?或者当用户不想再输入stringOff主题但很重要的是:不要使用
list
作为变量名,它将覆盖Python中的list()
。请不要使用list
作为变量名。另外,您的列表在开始时为空。。。所以循环永远不会执行,用应该执行的时间替换它。你的代码把我弄糊涂了,你想怎么做?什么是a
,你为什么a+=sth
?为什么要将列表元素附加到其自身?你真的想在list[a]
行中写入my_dict[a]
进行查找吗?你打算输入多少次?或者当用户不想输入更多stringOff主题但很重要的是:不要使用list
作为变量名,它将覆盖list()
在Python中。请不要将列表
用作变量名。另外,您的列表在开始时为空。。。所以循环永远不会执行,用应该执行的时间替换它。你的代码把我弄糊涂了,你想怎么做?什么是a
,你为什么a+=sth
?为什么要将列表元素附加到其自身?您真的想在list[a]
行中写入my_dict[a]
以进行查找吗?---------------------------------------------------------------------------------------------------------------value错误回溯(最近一次调用)in()------>1 n=int(input())2 3 my_list=list()4用于范围(n)内的i:5 my_str=input('Enter string')ValueError:以10为基数的int()的文本无效:“阿尔及利亚”您在第一行中输入了什么----------------------------------------------------------------------ValueError回溯(最近一次调用最后一次)in()--->1 n=int(input())2 3 my_list=list()4表示范围(n)内的i:5 my_str=input('Enter string')值错误:以10为基数的int()的文本无效:“阿尔及利亚”您在第一行中输入了什么