Silly newbie question - Carrot character (^)
Philip Semanchuk
philip at semanchuk.com
Fri Nov 5 10:12:05 EDT 2010
On Nov 5, 2010, at 9:43 AM, Matty Sarro wrote:
> Hey Everyone,
> Just curious - I'm working on a program which includes a calculation of a
> circle, and I found myself trying to use pi*radius^2, and getting errors
> that data types float and int are unsupported for "^". Now, I realized I was
> making the mistake of using '^' instead of "**". I've corrected this and its
> now working. However, what exactly does ^ do? I know its used in regular
> expressions but I can't seem to find anything about using it as an operator.
> Sadly my google foo is failing since the character gets filtered out.
As others have said, ^ is for XOR. That's buried here in the documentation:
http://docs.python.org/release/2.7/reference/expressions.html#binary-bitwise-operations
Not that I would have expected you to find it there since that's pretty dense. In fact, older versions of the Python doc used to describe this section as "for language lawyers" but I see they've changed that now.
BTW the more common name for this character is caret (ka-RAY).
Cheers
Philip
More information about the Python-list
mailing list