how to check if a number is in a list python?

Today, We want to share with you python check if value in list.In this post we will show you python check if list contains elements of another list, hear for Fastest way to check if a value exists in a list we will give you demo and example for implement.In this post, we will learn about how to check if a number is in a list python? with an example.

Python : How to check if list contains value

Example 1: Check If List Item Exists

thislist = ["ajay", "bhavika", "chaggan"]
if "ajay" in thislist:
  print("Yes, 'ajay' is in the members list")

Example

# List  
totalcontentdatalist= ['list' , 'of', 'different', 'strings', 'to', 'find','to']

Check if value exist in List using ‘in’ operator

{value} in [list]
if 'list' in totalcontentdatalist:
    print('"list" is found in totalcontentdatalist')
if 'ajay' not in totalcontentdatalist:
    print('"ajay" is not found in totalcontentdatalist')

Check if value exist in list using list.count() function

list.count('value')
if totalcontentdatalist.count('to') > 0:
   print('"to" exists in totalcontentdatalist');

Python Program to Check if a Number is Odd or Even

num = int(input("Enter a number: "))
if (num % 2) == 0:
   print("{0} is Even".format(num))
else:
   print("{0} is Odd".format(num))

I hope you get an idea about Python Program to Check if a Number is Odd or Even.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment