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

What it means for the incorrect usage of "and" to check multiple items in a list?

I understand the proper way to check multiple items in a list is to use any and all, like this.

A slow method is shown below in the second if-statement (if 'e' in lst and 'b' in lst). However, the first if-statement below does not return any error, so what actually it is doing? i.e. what is the exact meaning of if 'e' and 'b' in lst?

lst = ['a','b','c']
if 'e' and 'b' in lst:
    print(1)
if 'e' in lst and 'b' in lst:
    print(2)

>>> 1

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 :

It first checks for if ‘e’ is true and (as it has a value it evaluates to True) and then checks for ‘b’ in the meat which is true so it evaluates to true as well and prints 1

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