In [23]:
from IPython.core.display import display, HTML
display(HTML("<style>.container { width:103% !important;margin-left: -2%; }</style>"))
In [1]:
l1=[1,2,3,4]
l1
Out[1]:
[1, 2, 3, 4]
In [14]:
check_element=5
In [15]:
pos=check_element in l1
pos
Out[15]:
False
In [17]:
if pos:
print("Element " + str(check_element) + " is present in the list")
else:
print("Element " + str(check_element) + " is not present in the list")
Element 5 is not present in the list
Creating the function¶
In [20]:
def check_element(L1,x):
l1=[]
l1=L1
check_element = x
pos=check_element in l1
if pos:
print("Element " + str(check_element) + " is present in the list")
else:
print("Element " + str(check_element) + " is not present in the list")
In [21]:
check_element([1,2,3],2)
Element 2 is present in the list
In [22]:
check_element([1,2,3],4)
Element 4 is not present in the list