0
i want to print using index method in python's for loop.can anyone help me
4 Réponses
+ 2
It's possible, though I'm not sure it's useful. You can say
lst = ["fruits", "two", "three"]
print(lst[lst.index("two")])
which will print "two", but you may as well just say print("two") which is quicker and won't return an error if "two" isn't in lst.
+ 1
The index() method returns a number. So ["fruits", "two", "three"].index("two") would return 1 - since "two" is at index 1 of that list.
Why do you want to print using this particular method?
0
i want to know its possible or not?
0
thanks