SubhanUllah Posted October 4, 2022 Report Posted October 4, 2022 If you're sure the element is in the list, you really don't need an if statement… fruits = ['Mango', 'Apple', 'Orange', 'Pear', 'Peach'] print(fruits.index('Pear')) But here you go… fruits = ['Mango', 'Apple', 'Orange', 'Pear', 'Peach'] if 'Pear' in fruits: print(fruits.index('Pear')) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.