List Index Find in Python
Level 379 keystrokes
This finds the index of a value in a list. The index() method returns the position of the first occurrence.
Python code
# Create a list of numbers1nums = [10, 20, 30, 40, 50]# index() finds the position of the value 30# Returns 2 because 30 is at index 2 (0-based)2idx = nums.index(30)# Print the result with f-string3print(f"30 is at index {idx}")Output
30 is at index 2
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this Python code and how often they appear.
,× 4"× 2(× 2)× 2=× 2.× 1[× 1]× 1{× 1}× 1