Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
+2 votes
5 views
in Python by (4k points)
edited by

How can someone get a index (1) in Python for a list ["qwe", "asd", "zxc"] and an item "asd" in the list?

2 Answers

0 votes
by (46k points)
edited by

You can find many methods to perform this task, let me help you with a few:

  • You can use the help function (useful for beginners) 

       >>> help(["foo", "bar", "baz"])

Help on list object:

class list(object)
...

 |
|  index(...)
|      L.index(value, [start, [stop]]) -> integer -- return first index of value
|

This method is quite useful and lead to the method you are looking for.

  •  You can use enumerate()

  indexes = [i for i,y in enumerate(ys) if y == 'asd'] 

 If you have any doubts, put them down below in the comments, cheers. 

0 votes
by (106k points)

You should use the interactive help function:

>>> help(["foo", "bar", "baz"])

Help on list object:

class list(object)

 ...

 |

 |  index(...)

 |      L.index(value, [start, [stop]]) ->       integer -- return first index of value

 |

which will often lead you to the method you are looking for.

You can use the following video tutorials to clear all your doubts:-

Learn in detail about Python by enrolling in Intellipaat Python Course online and upskill.

Related questions

0 votes
1 answer
+3 votes
2 answers
+3 votes
2 answers
+2 votes
3 answers

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...