Python: Avoid short circuit evaluation

前端 未结 3 1428
暖寄归人
暖寄归人 2020-12-10 01:10

This is a problem that occured to me while working on a Django project. It\'s about form validation.

In Django, when you have a submitted form, you can call is

3条回答
  •  死守一世寂寞
    2020-12-10 01:52

    You can simply use the binary & operator, which will do a non-short-circuit logical AND on bools.

    if form1.is_valid() & form2.is_valid():
       ...
    

提交回复
热议问题