How to Toggle a Value?
What Is the Most Efficient Way to Toggle Between 0 and 1? 1 17 Answers Solution Using Not If the Values Are Boolean, the Fastest Approach Is to Use the Not...
What is the most efficient way to toggle between 0 and 1?
17 Answers
Must Read
Solution using NOT
If the values are boolean, the fastest approach is to use the not operator:
>>> x = True
>>> x = not x # toggle
>>> x
False
>>> x = not x # toggle
>>> x
True
>>> x = not x # toggle
>>> x
False