6 ms·
I just figured this out today but the pass by reference and pass by value thing in Python. I understood that Python variables in the same scope can refer to the
by stefanpie 9y ago
I just figured this out today but the pass by reference and pass by value thing in Python. I understood that Python variables in the same scope can refer to the same memory object, just the name is different. However when you pass the into classes and fuctions, mutable types are pass by reference and imutable types are pass by value. I just came to this realization after spending hours looking at gui code trying to figure out why some variables form a parent object we're not changing when passed into another class and modified.
- zurn 9y agoEverything is passed by reference in Python. But there are no methods to modify values of immutable objects like strings or numbers. (Variable assignment, as in foo = bar, always just assigns a reference, it doesn't mutate objects or copy values.)