+ 2

How this code works?

x=3 b=7 b=--x print(b) #ouput=3 but why can anyone explain this code that how is worked.

22nd Apr 2018, 5:06 PM
Maninder $ingh
Maninder $ingh - avatar
4 Antworten
+ 18
In Python : increment or decrement are not allowed ... so the b is assigned the value of x without decrement... check out this link for more 👇 https://www.geeksforgeeks.org/g-fact-21-increment-and-decrement-operators-in-python/
22nd Apr 2018, 5:21 PM
🌛DT🌜
🌛DT🌜 - avatar
+ 2
b=--x means you assign a new value to variable b which is minus minus x = 3 b-=x means you decrement the value of b by x which is b-x=4
23rd Apr 2018, 6:30 PM
tamaslud
tamaslud - avatar