python中关于 and 与or的优先级举例

最近在判断语句上遇到了很基础的麻烦。

if search_date_one == None or search_date_one ==''  and  search_date_two == None or  search_date_two =='' :

         pass

elif search_date_one ==None or search_date_one =='':

         pass

发现当search_date_one输入框为空且search_date_two不为空时,并不能执行第二条语句。

原来是and  or  逻辑运算符优先级问题。改为:

if search_date_one == None and search_date_two == None or search_date_one ==''  and  search_date_two =='' :

        pass

猜你喜欢

转载自blog.csdn.net/qq_37816453/article/details/82183924