首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >PythonMath-TypeError:‘NoneType’对象不可订阅怎么办?

PythonMath-TypeError:‘NoneType’对象不可订阅怎么办?
EN

Stack Overflow用户
提问于 2018-08-15 01:59:12
回答 2查看 0关注 0票数 0

我正在为数学做一个小程序(没有什么特别的原因,只是有点想要),我遇到了一个错误“TypeError:‘NoneType’对象是不可订阅的。

代码语言:txt
复制
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)

错误:

代码语言:txt
复制
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
EN

Stack Overflow用户

发布于 2018-08-15 11:18:52

代码语言:txt
复制
lista = list.sort(lista)

这应该是

代码语言:txt
复制
lista.sort()

The .sort()方法不返回任何值。

代码语言:txt
复制
sorted_list = sorted(lista)
票数 0
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/-100002174

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档