normal list 'type' object is not subscriptable

13,005

range is a function it should be range(1,20)

That is the line for n in range[1,20]: should read

for n in range(1,20):

As you can see in the documentation

range(start, stop[, step])
This is a versatile function to create lists containing arithmetic progressions

(Emphasis mine)

A small demo

>>> 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
Share:
13,005
Sahoory
Author by

Sahoory

Updated on June 12, 2022

Comments

  • Sahoory
    Sahoory about 2 years
    numbers = [2 , 5 , 10]
    for n in range[1,20]:
        if n in numbers:
            continue
        print (n)
    

    I'm getting this error

    C:\Python34\python.exe "F:/google drive/3d projects/python/untitled/0001.py"
    Traceback (most recent call last):
    File "F:/google drive/3d projects/python/untitled/0001.py", line 2, in <module>
            for n in range[1,20]:
        TypeError: 'type' object is not subscriptable
    

    looked for an answer but didnt find it im new to python so dont be angry if this is a stupid qustion the weird thing this code is used exactly on a tutorial on youtube and its working i use pycharm is there any thing wrong in my python app or ide