0

I have recently started coding on python.. Today I came across a statement 10--2.. At first, I thought it might give an error but when I compiled the code the answer came out to be 12.. I don't have any clue how was this possible.. I have knowledge about increment and decrement operators but this doesn't make sense.. If anyone of you can describe the logic it will be of great help..

1
  • 1
    Python does not have a -- decrement operator. What you see is actually 10-(-2). Commented Jul 7, 2018 at 8:05

1 Answer 1

2

There is no increment or decrement operators (i++, i--) in Python unlike some other languages(c, Java)

If you want to do increment you need to do something like i = i+1 or simply i += 1
Here what happens is Python treats 10--2 as 10 - (-2),

That is
10 - (-2) = 10 + 2 = 12

Similarly,
10-+2 = 10 - 2 = 8

You can even do

10++2 = 12
10-+2 = 8
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.