w3resource

Python: Find the index of an item in a specified list

Python List: Exercise - 22 with Solution

Write a Python program to find the index of an item in a specified list.

Example - 1 :

Python: Find the index of an item in a specified list

Example - 2 :

Python: Find the index of an item in a specified list

Example - 3 :

Python: Find the index of an item in a specified list

Sample Solution:

Python Code:

# Define a list 'num' containing a sequence of numbers
num = [10, 30, 4, -6]

# Use the 'index' method to find the index of the element with the value 30 in the list 'num'
# The result will be the position of the first occurrence of 30 in the list
print(num.index(30))

Sample Output:

1

Flowchart:

Flowchart: Find the index of an item in a specified list

Python Code Editor:

Previous: Write a Python program to convert a list of characters into a string.
Next: Write a Python program to flatten a shallow list.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://198.211.115.131/python-exercises/list/python-data-type-list-exercise-22.php