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
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>>
In your second example, the string "Lorem" evaluates to True and is being printed without checking if "aliqua" appears. Try searching for both.
any([x in string for x in ["Lorem", "aliqua"]])
>> True
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With