How come 2 ^ 3 = 1 in python 3.9

297 Views Asked by At

Shouldn't it be 8?

The same thing goes with 3 ^ 2. I also got 1.

This is confusing... enter image description here

2

There are 2 best solutions below

0
Seth On BEST ANSWER

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.

0
Wasif On

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

pow(3,2)

Or use **

3**2