How to toggle a value in Python

后端 未结 17 953
梦谈多话
梦谈多话 2020-12-07 07:46

What is the most efficient way to toggle between 0 and 1?

17条回答
  •  自闭症患者
    2020-12-07 08:13

    The easiest way to toggle between 1 and 0 is to subtract from 1.

    def toggle(value):
        return 1 - value
    

提交回复
热议问题