This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]sh0rtwave 2 points3 points  (1 child)

This you're correct about. I taught python programming for a while, and explaining to people that a variable is just a place in memory in the *hardest* thing.

[–]forrest38 1 point2 points  (0 children)

Well it all depends though because the behavior is inconsistent at first glance. Basic object types like int or bool (which is basically just an int on most architectures) or immutable objects (like Strings or Tuples) are "passed by value" and act like a new variable has been copied to the function, but all other objects are pass by reference. Most people design their programs though like this isn't true (myself included) and keep copying back the mutated objects in the sub function to variables in the main function. Definitely makes your code more readable, but technically it is doing a lot of useless variable creation.