Python design pattern for many conditions

前端 未结 3 1199
失恋的感觉
失恋的感觉 2021-02-05 14:32

What is the recommended structure to write validate functions with many conditions? See these two examples. The first looks ugly, the second isn\'t very common, perhaps because

3条回答
  •  醉酒成梦
    2021-02-05 15:13

    def valid(value):
        return (is_this(value)
                and that(value)
                and other(value))
    

    and operator exhibits "short-circuit" behavior in Python.

提交回复
热议问题