Write a Python program to find the Index position of a specified element and print it. And if the specified element is not present then print -1 as

Question

Write a Python program to find the Index position of a specified element and print it. And if the specified element is not present then print -1 as
🧐 Not the exact question you are looking for?Go ask a question

Solution 1

Sure, here is a simple Python program that finds the index position of a specified element in a list. If the element is not present, it prints -1.

def find_index(lst, element):
    try:
        index = lst.index(element)
    except ValueError:
        index = -1
    return index

# Test t
    Knowee AI StudyGPT is a powerful AI-powered study tool designed to help you to solve study prob
Knowee AI StudyGPT is a powerful AI-powered study tool designed to help you to solve study problem.
Knowee AI StudyGPT is a powerful AI-powered study tool designed to help you to solve study problem.
Knowee AI StudyGPT is a powerful AI-powered study tool designed to help you to solve study problem.
Knowee AI StudyGPT is a powerful AI-powered study tool designed to help you to solv

This problem has been solved

Similar Questions

Write a Python program to find the Index position of a specified element and print it. And if the specified element is not present then print -1 as

What is the output of the following Python program?index = "Ability is a poor man's wealth".find("w")print(index)Question 1Select one:a.24b.0c.23d.-1

What is the output of the following Python program?index = "Ability is a poor man's wealth".find("W")print(index)Question 3Select one:a.24b.0c.23d.-1

What is the output of the following Python program?index = "Ability is a poor man's wealth".find("w")print(index)Question 7Select one:a.24b.0c.23d.-1

Write a program for reading a position and deleting a character at that specified location in a given string

1/3