Firstly, I apologise for the stupid question or any errors in my post! (This is my first post!)
Secondly, I have tried to look up the answer to this on Stack Overflow and also the RealPython website (Logical Expressions) but I still can't seem to wrap my head around why this piece of code returns a "True" to the last (uncommented) function call?
I am trying to answer the following question from the Ebook "Introduction to computation and programming using Python" -
"Write a function isIn that accepts two strings as arguments and returns True if either string occurs anywhere in the other, and False otherwise. Hint: you might want to use the built-in str operation in."
If anyone can explain (in layman terms) why the below piece of code is returning "True" to the last function call, I would be very grateful - Again apologies for the stupid question!
def isIn(string1, string2):
"""Input two strings
Returns 'True' if either strings are within each other
"""
if string1 in string2 or string2 not in string1:
return True
else:
return False
# isIn('hello', 'hello') # Prints True
# isIn('hello', 'hello world') # Prints True
isIn('hello world', 'world hello') # Prints True