PDA

View Full Version : what does this mean?



MelDJ
October 21st, 2009, 02:24 PM
i did this with python:
>>> print 4^2
6
>>> print 4^6
2

does the ^ mean minus?
and is python unable to show negative numbers?

GeneralZod
October 21st, 2009, 02:33 PM
i did this with python:
>>> print 4^2
6
>>> print 4^6
2

does the ^ mean minus?
and is python unable to show negative numbers?

According to this:

http://docs.python.org/library/operator.html

it is "bitwise exclusive OR" (http://en.wikipedia.org/wiki/Xor).

forrestcupp
October 21st, 2009, 02:35 PM
^ is a bitwise XOR operator. That means in binary, if exactly one of the 2 statements is true, the answer is true. Otherwise the answer is false.

4 = 0100
2 = 0010
XOR
6 = 0110


4 = 0100
6 = 0110
XOR
2 = 0010

MelDJ
October 21st, 2009, 02:38 PM
suddenly the boolean algebra i learn at school makes sense. :)
thanks. just taking my baby steps into programming:KS

Warpnow
October 21st, 2009, 02:43 PM
The free book byte of python has a chart in it. I'm also learning python. Started reading the book yesterday, and the first thing I coded was a compound interest generator. That book is great.

I just think its odd that powers are ** not ^, totally feels nonintuitive. Also the distinction between intergers and floating points seems odd to me. Intergers don't seem very useful to me.

MelDJ
October 21st, 2009, 02:50 PM
i did not understand anything you said!:). i am following the full circle magazine's tutorials. i seem to be a snail compared to you:rolleyes:

jespdj
October 21st, 2009, 03:45 PM
does the ^ mean minus?
and is python unable to show negative numbers?
Does the ^ mean minus? Is 4 - 2 = 6, or 4 - 6 = 2? Question answered... :P

Ofcourse Python is not unable to show negative numbers, that would be totally silly.

forrestcupp
October 21st, 2009, 07:28 PM
I just think its odd that powers are ** not ^, totally feels nonintuitive. Also the distinction between intergers and floating points seems odd to me. Intergers don't seem very useful to me.
I agree about the powers thing. Coming from Commodore BASIC, I was used to ^ being for powers, too.

But I totally disagree about integers. When you start coming up with a lot of real world algorithms, you'll stumble across thousands of reasons to use integers.

Tibuda
October 21st, 2009, 07:36 PM
Also the distinction between intergers and floating points seems odd to me. Intergers don't seem very useful to me.

It is a matter of storage of the data. There are only two integers between 0 and 1, but there are infinite real numbers.

emigrant
October 21st, 2009, 07:40 PM
The free book byte of python has a chart in it. I'm also learning python. Started reading the book yesterday, and the first thing I coded was a compound interest generator. That book is great.

I just think its odd that powers are ** not ^, totally feels nonintuitive. Also the distinction between intergers and floating points seems odd to me. Intergers don't seem very useful to me.

can you please give a link for the book?
thank you.

j.bell730
October 21st, 2009, 08:09 PM
can you please give a link for the book?
thank you.

http://tinyurl.com/ygzoduz

emigrant
October 22nd, 2009, 09:12 AM
j.bell730 (http://ubuntuforums.org/member.php?u=563127), thanks for the help.
for those who need a direct link:
http://www.google.com/url?sa=t&source=web&ct=res&cd=4&ved=0CBoQFjAD&url=http%3A%2F%2Fwww.ibiblio.org%2Fg2swap%2Fbyteof python%2Ffiles%2F120%2Fbyteofpython_120.pdf&ei=ohLgSsWTGNLn-QaS6_CsCw&usg=AFQjCNHp7ZTqo0_e8WqSjtbsTez_aORjeQ&sig2=XJHqq5w0zN2c0sjjPfenHg