‘float’ object is not subscriptable is a Python type error which occurs when you try to access “index” on float variables.
a = 1.0 print(str(a))
This code will throw,
'float' object is not subscriptable error because here we have assigned
a = 1.0 which means
a is a float value. In the next line, we are printing the 0th index of
print(str(a)), which is incorrect.
The error screen will look like this –
Arrays needs to be defined explicitly because, internally, they are not a value else the location of values. It means an array variable holds the address in memory location from where your first element starts.
So, the right way of implementing the above code is –
a = ['Ironman', 'Captain America', 'Thor', 'Hulk'] print(str(a)) // Output: Ironman
The live demo might not work in private window.