python - Python,浮点错误:+ 的不支持的操作数类型:“浮点”和“列表”
问题描述
我设置了以下课程:
class StatoPatrimoniale(models.Model):
reference_date=models.DateField()
cassa=models.DecimalField()
我设置了以下功能:
def stato_patrimoniale(request):
now=datetime.datetime.now()
last_account_year=float(now.year)-1
list_diff=[]
list_diff = float(StatoPatrimoniale.objects.filter(reference_date__year=last_account_year).values_list('cassa')[0][0])
但是python给了我以下错误:
unsupported operand type(s) for +: 'float' and 'list'
list_diff = float(StatoPatrimoniale.objects.filter(reference_date__year=last_account_year).values_list('cassa')[0][0])
为什么?问题出在哪里?
解决方案
我重现了错误:
TypeError: unsupported operand type(s) for +: 'float' and 'list'
但不是上面共享的代码。相反,我提出:
list_diff = float() + list_diff
list_diff 是一个列表,而 float() 是浮点数,你不能那样做
将其替换为
list_diff.append(float())
推荐阅读
- javascript - Javascript 中的简单关卡设计:如何在第 N 个问题后询问用户是否要继续游戏?
- docker - 构建的图像在之后立即启动并退出
- reactjs - 我收到解析错误:VS 代码中出现意外的令牌
- python - 修改多维数组(Python)
- javascript - 在 Enquirer CLI Prompt 中填写问题和答案字段
- c# - Firebase Unity:如何处理没有互联网连接的情况
- django - 在一个 Django 项目中拥有 DEV、TEST、PROD 环境的最佳方式
- javascript - 为什么导航栏不在 DOM 中呈现
- python - 泛型类型类的正确类型提示
- xml - 在 PowerShell 中,如何定义字符范围,包括 (dash -) 反斜杠 \ az、AZ、0-9?