Silly newbie question - Carrot character (^)

Shashwat Anand anand.shashwat at gmail.com
Fri Nov 5 10:02:52 EDT 2010


On Fri, Nov 5, 2010 at 7:26 PM, Krister Svanlund <krister.svanlund at gmail.com
> wrote:

> On Fri, Nov 5, 2010 at 2:43 PM, Matty Sarro <msarro at gmail.com> 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.
>
> It's a binary operator i think... something like xor.
>

Yes. Infact '^' is binary XOR.

>>> a = 4
>>> bin(a)
'0b100'
>>> b = 5
>>> bin(b)
'0b101'
>>> a ^ b
1

100 ^ 101 = 001



> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
~l0nwlf
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20101105/43847cf2/attachment-0001.html>


More information about the Python-list mailing list