0

i want to print using index method in python's for loop.can anyone help me

https://code.sololearn.com/cIH5QWQyQ6im/?ref=app

4th Apr 2020, 2:55 PM
HAMZA
4 Answers
+ 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.
4th Apr 2020, 3:18 PM
Russ
Russ - avatar
+ 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?
4th Apr 2020, 3:03 PM
Russ
Russ - avatar
0
i want to know its possible or not?
4th Apr 2020, 3:12 PM
HAMZA
0
thanks
4th Apr 2020, 3:24 PM
HAMZA