Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to get if statement to print a value inside array

In this example, I am trying to make it so that if variable == one of the values in the array, it prints "This Works".

array = [1, 2]

one = 1
two = 2

def trying():
    if one == array:
        print("This Works")

print(trying())

I understand that one and array isn’t the same, but how do I go about getting one and the value 1 to equal, so that this code works

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Try with in instead of ==,

array = [1, 2]

one = 1
two = 2

def trying():
    if one in array:
        print("This Works")

print(trying())
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading