Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (47.6k points)
edited by

I'm making a small program for math (no particular reason, just kind of wanted to) and I ran into the error "TypeError: 'NoneType' object is not subscribable.

I have never before seen this error, so I have no idea what it means.

import math 

print("The format you should consider:")

print str("value 1a")+str(" + ")+str("value 2")+str(" = ")+str("value 3a ")+str("value 4")+str("\n") 

print("Do not include the letters in the input, it automatically adds them") 

v1 = input("Value 1: ") 

v2 = input("Value 2: ")

v3 = input("Value 3: ") 

v4 = input("Value 4: ") 

lista = [v1, v3] 

lista = list.sort(lista) 

a = lista[1] - lista[0] 

list = [v2, v4] 

list = list.sort(list) 

b = list[1] = list[0] 

print str(a)+str("a")+str(" = ")+str(b)

The error:

Traceback (most recent call last): File "C:/Users/Nathan/Documents/Python/New thing", line 16, in <module> 

a = lista[1] - lista[0] 

TypeError: 'NoneType' object is not subscriptable

2 Answers

0 votes
by (106k points)
edited by

To get rid of the error you can use lista.sort()method:-

The .sort() method is in place, and returns None. If you want something not in-place, which returns a value, you could use

sorted_list = sorted(lista)

To know more about this you can have a look at the following video tutorial:-

If you want to learn python,visit this python tutorial and Python Certification.

0 votes
by (140 points)

In general, the error means that you attempted to index an object that doesn't have that functionality. You are trying to subscript an object which you think is a list or dict, but actually is None. NoneType is the type of the None object which represents a lack of value, for example, a function that does not explicitly return a value will return None. 'NoneType' object is not subscriptable is the one thrown by python when you use the square bracket notation object[key] where an object doesn't define the __getitem__ method .

If you wish to learn more about Python, visit Python tutorial and Python course by Intellipaat.

by (100 points)
This is really a nice and informative, containing all information and also has a great impact on the new technology. Thanks for sharing it.

Browse Categories

...