本文介紹了TypeError:“浮動"對象不可下標(biāo)的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
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]
基本上,我有一個輸入,用戶將輸入一個數(shù)字值(浮點輸入),然后它將所有上述列表索引設(shè)置為該值.出于某種原因,我無法在沒有提出以下建議的情況下設(shè)置它們:
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]
是一個浮點數(shù).PriceList[0][1]
正在嘗試訪問浮點數(shù)的第一個元素.相反,做
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
這篇關(guān)于TypeError:“浮動"對象不可下標(biāo)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!