Simulated Pointers With Mutable Types
In this lesson, you’ll simulate pointer behavior in Python using a mutable object type. This is not actual pointer behavior. These operations are more memory expensive than they would be in C.
I’m going to use the mutable list to modify the value of the immutable integer inside of it. To do that, I’ll define a new function called
add_one(), which will take in some list and add 1 to the value inside of it.
00:41 It looks like things worked as expected. We incremented the value inside the list by 1. But is this any more memory efficient? Not really. We simulated pointer behavior by passing the function an object it could mutate directly, but it still had to increment the immutable type inside the object.
Become a Member to join the conversation.