Categories
Python Answers

How to get the logical xor of two variables in Python?

Spread the love

Sometimes, we want to get the logical xor of two variables in Python.

In this article, we’ll look at how to get the logical xor of two variables in Python.

How to get the logical xor of two variables in Python?

To get the logical xor of two variables in Python, we can use the ^ operator.

For instance, we write

bool(a) ^ bool(b)

to return the xor result of 2 booleans with ^.

Conclusion

To get the logical xor of two variables in Python, we can use the ^ operator.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *