Python Practice › List Programs › Program 39

Check if an element exists

EasyList Programs · 39 of 100

Write a Python program to check whether an element exists in a list.

Advertisement
Input
[3, 9, 27], check 9 and 4
Output
9 exists
4 does not exist

Approach

  1. Use in.

Solution

Python
numbers = [3, 9, 27]for x in [9, 4]:    print(x, "exists" if x in numbers else "does not exist")
Output
9 exists
4 does not exist

Learn the concept

New to this topic? Read the lesson, then come back.

More list programs

← All 100 List Programs

Leave a Comment