TypeError:“浮动"对象不可下标

TypeError: #39;float#39; object is not subscriptable(TypeError:“浮动对象不可下标)
本文介绍了TypeError:“浮动"对象不可下标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

PizzaChange=float(input("What would you like the new price for all standard pizzas to be? "))      
PriceList[0][1][2][3][4][5][6]=[PizzaChange]  
PriceList[7][8][9][10][11]=[PizzaChange+3]

基本上,我有一个输入,用户将输入一个数字值(浮点输入),然后它将所有上述列表索引设置为该值.出于某种原因,我无法在没有提出以下建议的情况下设置它们:

Basically I have an input that a user will put a number values (float input) into, then it will set all of these aforementioned list indexes to that value. For some reason I can't get it to set them without coming up with a:

TypeError: 'float' object is not subscriptable

错误.我做错了什么还是我只是看错了?

error. Am I doing something wrong or am I just looking at it the wrong way?

推荐答案

PriceList[0] 是一个浮点数.PriceList[0][1] 正在尝试访问浮点数的第一个元素.相反,做

PriceList[0] is a float. PriceList[0][1] is trying to access the first element of a float. Instead, do

PriceList[0] = PriceList[1] = ...code omitted... = PriceList[6] = PizzaChange

PriceList[0:7] = [PizzaChange]*7

这篇关于TypeError:“浮动"对象不可下标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

【网站声明】本站部分内容来源于互联网,旨在帮助大家更快的解决问题,如果有图片或者内容侵犯了您的权益,请联系我们删除处理,感谢您的支持!

相关文档推荐

Why I cannot make an insert to Python list?(为什么我不能插入 Python 列表?)
Insert a column at the beginning (leftmost end) of a DataFrame(在 DataFrame 的开头(最左端)插入一列)
Python psycopg2 not inserting into postgresql table(Python psycopg2 没有插入到 postgresql 表中)
list extend() to index, inserting list elements not only to the end(list extend() 索引,不仅将列表元素插入到末尾)
How to add element in Python to the end of list using list.insert?(如何使用 list.insert 将 Python 中的元素添加到列表末尾?)
Insert element in Python list after every nth element(在每个第 n 个元素之后插入 Python 列表中的元素)