# Order of operations

1. Sep 13, 2015

### Mr Davis 97

I have the following table for order of operations in Python. It all makes sense except for the unary operation negation. What does it mean that the order of precedence is from right to left? Can I have an example?

Symbols - Operator - Type Order of precedence

( ) Parentheses Highest

- Unary (from right to left)

*, /, //, % Multiplicative (from left to right)

+, - Additive (from left to right)

2. Sep 13, 2015

### DaveC426913

!false
means: false > not
which means true.

!!false
means false > not > not
which means false

3. Sep 13, 2015

### Staff: Mentor

The left to right or right to left business describes how an expression using a given operator associates, and is not related to the order of precedence. For example, the + additive operator associates left to right. This means that a + b + c is treated as if it had been written (a + b) + c.

The ~ bitwise "not"operator associates right to left. This means that the expression ~~x is evaluated as if it were written ~(~x). I didn't use the unary - for an example, because -- is a different operator (decrement).

4. Sep 13, 2015

### MrAnchovy

Example -~0 is evaluated right-to-left as -(~0) = -(-1) = 1 whereas left to right it would be ~(-0) = ~0 = -1.

5. Sep 13, 2015

### D H

Staff Emeritus
Not in python. There is no ! operator in python. The correct operator in python is no. And it doesn't mean false > not (whatever that means). not false in python means exactly what a naive reader would think it means, which is true.

Not in python. Here, a>b>c means exactly what a physicist or mathematician would read that to mean, as opposed to a computer scientist. In python, a>b>c means that b is between c (lower bound) and a (upper bound), exclusive of c and a.

Aside: Using tokens such as not in a non-reserved context is generally perceived as a bad thing in python. (A very bad thing; you will get yourself in deep trouble if you name a variable not or len.)

Last edited: Sep 13, 2015
6. Sep 13, 2015

### DaveC426913

Yeah. I prolly should have looked up the syntax of python before posting.

7. Sep 13, 2015

### Staff: Mentor

No it's not .

8. Sep 13, 2015

### DaveC426913

I see what you did there!

9. Sep 13, 2015

### D H

Staff Emeritus
Yes, it's not.