122982
is_active = True status = ~is_active # Returns -2, triggers warning Use code with caution. Copied to clipboard is_active = True status = not is_active # Returns False Use code with caution. Copied to clipboard Conclusion
This blog post addresses in the CPython repository, which focuses on extending the deprecation warning period for bitwise inversion on boolean types in Python. 122982
In Python, booleans are a subclass of integers. When you apply the bitwise NOT operator ( ~ ) to a boolean: ~True (which is ~1 ) evaluates to -2 . ~False (which is ~0 ) evaluates to -1 . is_active = True status = ~is_active # Returns
Keep an eye on your console for those DeprecationWarnings —they are there to help you stay ahead of the curve! 122982