简体   繁体   中英

Retrieving float values from the list in Python

I am trying to fetch the values from an list containing float values which throws the following error,

list = [0.98,0.97,0.95,0.96,0.99,0.99]


for a in list:
    if list[a] >=0.98:
        print("some output")

Error:

TypeError: list indices must be integers, not float 

a is already the value, so you can do:

for a in list:
    if a >=0.98:
        print("some output")

If it was the index, your code will work, but since it isn't, you have to do mine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM