在python中输入数组
def insurer_filter(request, name):
insname = InsName.objects.filter(name = name)
ins_name = Development.objects.filter(insurer = insname)
return render(request, 'insurer_filter.html', context = ins_name)
答案 0 :(得分:1)
当在python
中分配给特定索引的数组时,该索引应该已经存在。如果要向数组添加元素,可以使用append
。
看这个简单的例子:
Home = ["AAA"] // array with 1 element only (index 0)
Home[1] = "BBB" // will fails because index 1 not define
Home.append("CCC")
Home[1] = "BBB" // works
答案 1 :(得分:0)
您应该使用append方法将元素添加到列表中。
//throws error
Home = []
Home[1] = input("How many points did the Rangers score in quarter 2?: ")
//works
Home = []
Home.append(input("How many points did the Rangers score in quarter 2?: "))