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

print("string1" or "string2" in string) does not give Boolean result

why does print("Lorem" and "aliqua" in string ) Gives True. A Boolean,

But print("Lorem" or "aliqua" in string ) Gives ‘Lorem’. A String

string = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua"

print("Lorem" and "aliqua" in string )
>>> True

print("Lorem" or "aliqua" in string )
>>> Lorem

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:

print("Lorem" in string and "aliqua" in string )

And

print("Lorem" in string or "aliqua" in string )

Explanation:
The condition in string will always be true as it checks string is non empty.

>>> if "harsha":
...   print("hi")
...
hi
>>> if "":
...   print("hi")
...
<<No output>>
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