3 ms·
Which is what every language with a C inheritance does. += has always mutated the original value, I don't know why you expected it to be different. To me the r
by pikzen 11y ago
Which is what every language with a C inheritance does. += has always mutated the original value, I don't know why you expected it to be different.
To me the real wtf is the second, where python creates a variable with the same name and discards it.
- chei0aiV 11y agoWhich is what every language with a C inheritance does. Arguments are passed by value and put into ordinary variables, I don't know why you expected it to be different.
- ketralnis 11y agoWell no. What would you expect this code to do? void increment(int x) { x += 1; } void printit() { int y = 0; increment(y); printf("%d\n", y); } C doesn't have lists so I had to use an int here, but the Python example does the equivalent of that code printing 1, not 0. (But only for lists. That same Python code with ints does what you expect.)