Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
尝试在python上附加多维列表时出错_Python_List - Fatal编程技术网

尝试在python上附加多维列表时出错

尝试在python上附加多维列表时出错,python,list,Python,List,我试图将多维列表附加到一个空列表中。但不知怎的,它不起作用,终端向我显示了这个错误(TypeError:字符串索引必须是整数)。这是我的密码: dataUser = [] user = input('Input user : ') type = input('Type : ') category = input('Category : ') message = input('Message : ') dataUser.append([user[type,category,message] ])

我试图将多维列表附加到一个空列表中。但不知怎的,它不起作用,终端向我显示了这个错误(TypeError:字符串索引必须是整数)。这是我的密码:

dataUser = []
user = input('Input user : ')
type = input('Type : ')
category = input('Category : ')
message = input('Message : ')
dataUser.append([user[type,category,message] ])

改用字典。当你调用数组时,比如
user[x]
x是数组中元素的索引,但在字典中它是键之一

dataUser = []
user = {}
username = input('Input user : ')
user_type = input('Type : ')
category = input('Category : ')
message = input('Message : ')
user["name"]=username
user["type"]=user_type
user["category"] = category
user["message"] = message
dataUser.append(user)

print(user)
print(dataUser)

user[type,category,message]
对你意味着什么?改用字典。看看如何创建一个rip我不能使用字典他们告诉我用list来做。使用
dataUser.append([user,type,category,message])
谢谢你的回答,但很遗憾我不能使用字典。我只想知道错误消息的意思。如果您想使用列表,请将用户放在其他信息旁边,如
dataUser.append([user,type,category,message])