0

I am teaching myself python from Mike McGrath's 'python in easy steps' book. On the section talking about bitwise operators (| , &, ~, ^, >>, <<) it has you doing some moving of bits around. But when I try to use then tilde ~ I get a syntax error. But not for any of the other operators. Can someone please help a beginer and tell me what I'm doing wrong?

a = 10
b = 5
print('a =', a, '\tb=', b)

b = a ~ b

a = a ^ b
print('a=', a, '\tb=', b)
martineau
  • 119,623
  • 25
  • 170
  • 301
  • 4
    `~` is a thing you do to one number, not two. – user2357112 Mar 27 '21 at 14:50
  • In other words it's a [unary operator](https://en.wikipedia.org/wiki/Unary_operation). – martineau Mar 27 '21 at 15:00
  • In the [Python docs](https://docs.python.org/3/reference/expressions.html#unary-arithmetic-and-bitwise-operations) you can find `~` in the section unary operators but not in the section binary operators. – Thomas Sablik Mar 27 '21 at 15:02

1 Answers1

0

~ is a unary operator, so a ~ b is a no go.

Hoang
  • 167
  • 3
  • 12