Skip to content Skip to sidebar Skip to footer

How Come 2 ^ 3 = 1 In Python 3.9

Shouldn't it be 8? The same thing goes with 3 ^ 2. I also got 1. This is confusing...

Solution 1:

In Python, ^ is a bitwise XOR operator. I believe what you're looking for is the exponent operator, **. An example would be 2**3 which outputs 8, like I believe you were looking for.

Solution 2:

The ^ operator does a bitwise XOR operation. In python to do power calculation use pow() function:

pow(3,2)

Or use **

3**2

Post a Comment for "How Come 2 ^ 3 = 1 In Python 3.9"