This article mainly introduces the tips for returning TrueorFalse values in Python. This article describes the simplest method of writing conditional judgment statements. This article provides two simple methods, you can refer to the following code in the blog about substring yesterday:
You may have discovered that in Python 3, there is actually a way to complete the function with only one row:
The code is as follows:
>>> Def isSubstring2 (s1, s2 ):
Return True if s2.find (s1 )! =-1 else False
But... Can it be simpler?
How can we use Python to express conditional statements more easily? just for fun :)
One way is to use the list index:
The code is as follows:
>>> Def isSubstring2 (s1, s2 ):
Return [False, True] [s2.find (s1 )! =-1]
The principle is very simple. if the Boolean value True is evaluated as 1 by the index, and False is equal to 0, can it be simpler? Leave a message to me ;-)