Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.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_Python 3.x_Pycharm_Typeerror - Fatal编程技术网

Python 正常列表';类型';对象不可下标

Python 正常列表';类型';对象不可下标,python,list,python-3.x,pycharm,typeerror,Python,List,Python 3.x,Pycharm,Typeerror,我犯了这个错误 numbers = [2 , 5 , 10] for n in range[1,20]: if n in numbers: continue print (n) C:\Python34\python.exe“F:/google drive/3d projects/python/untitled/0001.py” 回溯(最近一次呼叫最后一次): 文件“F:/google drive/3d projects/python/untitled/0001.

我犯了这个错误

numbers = [2 , 5 , 10]
for n in range[1,20]:
    if n in numbers:
        continue
    print (n)
C:\Python34\python.exe“F:/google drive/3d projects/python/untitled/0001.py”
回溯(最近一次呼叫最后一次):
文件“F:/google drive/3d projects/python/untitled/0001.py”,第2行,在
对于[1,20]范围内的n:
TypeError:“type”对象不可下标
寻找答案,但没有发现,我是python新手,所以如果这是一个愚蠢的问题,请不要生气。奇怪的是,这段代码在youtube上的一个教程中被使用,并且正在运行
我使用pycharm我的python应用程序或ide中是否有任何错误

您需要使用括号而不是方括号,对于范围[1,20]中的n,您有
对于范围(1,20)中的n,这应该是

[106]中的

数字=[2,5,10]

对于范围(1,20)中的n:#范围
是一个函数,它应该是范围(1,20)

这是[1,20]范围内n的
行:
应为

In [106]:

numbers = [2 , 5 , 10]
for n in range(1,20): #<--
    if n in numbers:
        continue
    print (n)
1
3
4
6
7
8
9
11
12
13
14
15
16
17
18
19
正如你在照片中看到的那样

范围(开始、停止[、步骤])

这是一个多功能的函数,用于创建包含算术级数的列表

(强调矿山)

小型演示

for n in range(1,20):
for n in range(1,20):
>>> numbers = [2 , 5 , 10]
>>> for n in range(1,20): 
...    if n in numbers:
...        continue
...    print (n)
1
3
4
6
7
8
9
11
12
13
14
15
16
17
18
19