May-17-2021, 04:57 PM
I try to get a list item by feeding it with Int variable, but cannot find a way to do it.
# this one works cars = ["Audi", "Opel", "BMW"] for x,y in enumerate(cars): temp = int(x) print(cars[temp])But when I try to feed an item directly with a variable, I get an error. I want to use direct method in WebAutomation (looping and picking elements in HTML).
# this one not cars = ["Audi", "Opel", "BMW"] for x,y in enumerate(cars): print(cars["{}".format(int(x))])
Error:Exception has occurred: TypeError
list indices must be integers or slices, not str
File "C:\Users\stony\OneDrive\Stalinis kompiuteris\Python\smeliodeze.py", line 19, in <module>
print(cars["{}".format(int(x))])