TypeError:'float'对象不可订阅 [英] TypeError: 'float' object is not subscriptable

查看:1099
本文介绍了TypeError:'float'对象不可订阅的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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] 正在尝试访问float的第一个元素。相反,做

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:'float'对象不可订阅的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆