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

In this “list contains python” best post i learn to about different methods to check if a given ProductId exists in list or not using Python.

## How to Check if an item exists in list ?

Contents

here I give you best example for Fastest way to check if a value exists in a list using Python.

Suppose you mean python “list” contains python where you say “array”, you can do

```if item in my_list:
# whatever
```

### Check if object with specific value exists in List

```if(productListFirst.Any(a => a.Id == stringID))
{
//Your some Python logic goes here;
}
```

Also Read: python list contains

## Python Check If List Item Exists

use the in keyword:
here in this example to Check if “pakainfo” is Existing in the list contains python:

```thislist = ["pakainfo", "4cgandhi", "infinityknow"]
if "pakainfo" in thislist:
print("Yes, 'pakainfo' is in the Website list")
```

Also Read This π   Python Program to Check Armstrong Number

## With any Example

```productListFirst = [[-9, -1, 3], [11, -8],[-4,434,0]]
search_ProductId = -8

# Given list
print("Given List :\n", productListFirst)

print("ProductId to Find: ",search_ProductId)

# Using in
if any(search_ProductId in sublist for sublist in productListFirst):
print("Existing")
else:
print("Not Existing")
```

Output

```('Given List :\n', [[-9, -1, 3], [11, -8], [-4, 434, 0]])
('ProductId to Find: ', -8)
Existing
```

Also Read: convert string to array python

## With in Example

```productListFirst = [[-9, -1, 3], [11, -8],[-4,434,0]]
search_ProductId = -8

# Given list
print("Given List :\n", productListFirst)

print("ProductId to Find: ",search_ProductId)

# Using in
if search_ProductId in (item for sublist in productListFirst for item in sublist):
print("Existing")
else:
print("Not Existing")

search_ProductId = 13
print("New ProductId to Find: ",search_ProductId)

# Using in
if search_ProductId in (item for sublist in productListFirst for item in sublist):
print("Existing")
else:
print("Not Existing")
```

Free Live Chat for Any Issue

Output

```Given List :
[[-9, -1, 3], [11, -8], [-4, 434, 0]]
ProductId to Find: -8
Existing
New ProductId to Find: 13
Not Existing
```

Also Read This π   how to check if a number is in a list python?

## With chain Example

```from itertools import chain

productListFirst = [[-9, -1, 3], [11, -8],[-4,434,0]]
search_ProductId = -8

# Given list
print("Given List :\n", productListFirst)

print("ProductId to Find: ",search_ProductId)

# Using in
if search_ProductId in chain(*productListFirst):
print("Existing")
else:
print("Not Existing")

search_ProductId = 13
print("New ProductId to Find: ",search_ProductId)

# Using in
if search_ProductId in chain(*productListFirst):
print("Existing")
else:
print("Not Existing")
```

Output

```Given List :
[[-9, -1, 3], [11, -8], [-4, 434, 0]]
ProductId to Find: -8
Existing
New ProductId to Find: 13
Not Existing
```

Also Read: python developer resume Examples

Also Read: How to Use Time Sleep in Python Script?

Also Read: python unzip

Also Read: How to create a Directory in python ?