Python: if more than one of three things is true, return false

前端 未结 11 2543
温柔的废话
温柔的废话 2021-02-14 01:33

I\'m writing a django model that allows my site to have coupons.

Coupons can have three types: lifetime account voucher, certain period of months voucher, certain numb

11条回答
  •  悲&欢浪女
    2021-02-14 01:49

    How about

    if len(filter([self.months, self.dollars, self.lifetime])) > 1:
    ...
    

    I find it just as readable as a list comprehension with an if clause, and more concise.

提交回复
热议问题