Why 2--2 gives 4 in output? Can anyone explain this for me ? | Sololearn: Learn to code for FREE!
Nowy kurs! Każdy programista powinien nauczyć się Generative AI!
Wypróbuj darmową lekcję
0

Why 2--2 gives 4 in output? Can anyone explain this for me ?

13th Jul 2016, 9:10 PM
Shriram Moond
Shriram Moond - avatar
5 odpowiedzi
+ 5
Here the first '−' represents the binary subtraction operation, while the second '−' represents the unary negation of the 2 (or '−2' could be taken to mean the integer −2). Therefore, the expression is equal to : 2-(-2) which results in 4 as output
13th Jul 2016, 10:06 PM
LAVISH PATODI
LAVISH PATODI - avatar
+ 1
cause minus and minus give us plus
14th Jul 2016, 6:21 AM
Жасур Пулатов
Жасур Пулатов - avatar
+ 1
2-(-2) becomes 2+2 which is 4
14th Jul 2016, 9:03 AM
Ashwani
+ 1
Well In mathematics you would have learned that negative and negative equals to positive, same is the condition here you ask python to give output for 2(negative)(negative)2 which becomes 2(positive)2 and the answer is 4 which is displayed.
18th Jul 2016, 8:34 AM
MalikSami
MalikSami - avatar
0
2-(-2)
2nd Sep 2016, 6:15 PM
arun kumar
arun kumar - avatar