Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/306.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
如何使用oprator输入python向数组添加索引?_Python_Typeerror - Fatal编程技术网

如何使用oprator输入python向数组添加索引?

如何使用oprator输入python向数组添加索引?,python,typeerror,Python,Typeerror,这是源代码: while (1): num =input("please enter for array or for lunch index array enter\"lunch\"") hh=[] p=int(len(hh)) print(p) print(type(p)) if(num=="lunch"): print(hh) eli

这是源代码:

 while (1):
     num =input("please enter for array  or  for lunch index array enter\"lunch\"")
     hh=[]
     p=int(len(hh))
     print(p)
     print(type(p))
    
     if(num=="lunch"):
      print(hh)
     elif(num=="end"):
      break
     else:
       cc=0
       for cc in p :
        hh.append(i,num)
        cc+=1
     print(hh)
这就是我得到的错误:

Traceback (most recent call last):
  File "D:\python project\array.py", line 14, in <module>
    for cc in p :
TypeError: 'int' object is not iterable
为什么我会出现打字错误?
请解释什么是iterable…

iterable是具有多个项和支持的对象
所以列表、元组、字符串是可编辑的,整数不是

您试图迭代整数-什么不清楚?