New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Weird arithmetic with multiple +
and -
#319
Comments
Hmmmm >>> 1 + (-(+(-(+1)))) # 1 + 1
2
>>> 1 + (+(+(+(+(+1))))) # 1 + 1
2
>>> 1 - (-(-1)) # 1 - 1
0
>>> 1 - (-1) # 1 - (-1) == 1 + 1
2 >>> +5 // 2
2
>>> -5 // 2
-3 >>> 2 + (5 // 2) # 2 + (+5 // 2)
4
>>> 2 - ((-5) // 2) # 2 - (-5 // 2)
5
>>> 2 + ((-(-5)) // 2) # 2 + (+5 // 2)
4
>>> 2 - ((+(-5)) // 2) # 2 - (-5 // 2)
5
>>> 2 - ((-(+5)) // 2) # 2 - (-5 // 2)
5 |
Thank you for the breakdown with parenthesis @shiracamus. There is clear operator precedence. >>> 2 - ((-(+5)) // 2) # 2 - (-5 // 2)
5 The 2 signs |
Its meaning is ``I try using parentheses to check the priority.'' |
Hello. Cool collection of WTFs
I made a blog post about something that belongs in this collection.
I'd be happy to write up a section for it.
Where should I put it? Any suggestion? Maybe right before or after the "Not knot" section that also deals with order precedence?
TL;DR
This is all valid python:
It's all good an dandy until you use it with
//
and then things get weird:It's all explained by the operation precedence but it's very counter intuitive!
The text was updated successfully, but these errors were encountered: