Python 3 Script to Check If Element Exists in a List Using For Loop

Python 3 Script to Check If Element Exists in a List Using For Loop There may be many doubts when it comes to this article. We hope that after reading this article all doubts will be resolved. Let’s go to the article.

Python 3 Script to Check If Element Exists in a List Using For Loop

Python 3 Script to Check If Element Exists in a List Using For Loop

# Python code to demonstrate 
# checking of element existence 
# using loops and in 

# Initializing list 
test_list = [ 1, 6, 3, 5, 3, 4 ] 

print("Checking if 4 exists in list ( using loop ) : ") 

# Checking if 4 exists in list 
# using loop 
for i in test_list: 
    if(i == 4) : 
        print ("Element Exists") 

print("Checking if 4 exists in list ( using in ) : ") 

# Checking if 4 exists in list 
# using in 
if (4 in test_list): 
    print ("Element Exists")

Read Also: Python 3 Time Module Example Script to Check Performance and Time Taken By Python Code and Methods

Final Words

Python 3 Script to Check If Element Exists in a List Using For Loop We hope all your doubts about this topic will be resolved. See you again in the next article Thank you.

Hi, I'm Selva a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Deekshi. Here, I post about programming to help developers.

Share on:

Leave a Comment