Home > Article > Backend Development > Share the simplest way to write a conditional judgment statement in python
This article mainly introduces Python Tips for returning true or false values (True or False). This article discusses the simplest condition Judgment statement writing method. This article gives For two concise writing methods, friends who need it can refer to the following code:
def isLen(strString): if len(strString)>6: return True else: return False
Maybe you have discovered that in Python 3, there is actually a way to complete it in just one line
Function>>> def isLen(strString): return True if len(strString)>6 else False
But. . . Could it be simpler?
How to use Python to express conditional statements more easily, just
forfun :)One way is to use a list
Index>>> def isLen(strString): #这里注意false和true的位置, 多谢网友@小王的指正 return [False,True][len(strString)>6]
The principle is very simple. The Boolean value True is evaluated as 1 by index, and False is equal to 0. Can it be simpler?
The above is the detailed content of Share the simplest way to write a conditional judgment statement in python. For more information, please follow other related articles on the PHP Chinese website!