Python Memory Management and Tips Transcripts
Chapter: Python variables and memory
Lecture: Pass by value

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Let's look at that alternative example that we saw in C++, But now in Python. Remember what we did is we passed over the id
0:07 We said these are integers and we're just gonna compare them directly. And here's the same code in Python,
0:13 really The only difference is where the return value goes and whether it goes int p1_id or p1_id int. Right, this is the same basic code.
0:22 And if you print out p1_id or p2_id, it's gonna look just like the same thing that we had in C++, but it's not the same thing.
0:31 In Python, these are different than what we had in C++. In C++ they're just allocated as the program runs technically on the stack.
0:40 They're not passed by value, all sorts of stuff like that. So we're going to see that, actually, these also live out in memory, they're
0:48 dynamically allocated, they have to be cleaned up just like our person object was. So these are pointing out here in just the same way. In some sense,
0:57 does Python a Pointers? Python has more pointers than almost every other language,
1:01 right? Even things like numbers and integers or functions themselves or modules and source code all of those things are objects and pointers.
1:11 Even when they operate as basic numbers, like we have here these are basic numbers that are allocated dynamically out in memory.


Talk Python's Mastodon Michael Kennedy's Mastodon