Python Practice › Set Programs › Program 5

Is an element in a set?

EasySet Programs · 5 of 48

Write a Python program to check whether an element is in a set.

Advertisement
Input
{2, 4, 6}, check 4 and 5
Output
True False

Approach

  1. in is very fast on sets.

Solution

Python
s = {2, 4, 6}print(4 in s, 5 in s)
Output
True False

Learn the concept

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

More set programs

← All 48 Set Programs

Leave a Comment