Python Memory Management and Tips Transcripts
Chapter: Python variables and memory
Lecture: Pass by value
0:00 Let's look at that alternative example that we saw in C++,
0:03 But now in Python. Remember what we did is we passed over the id
0:06 We said these are integers and we're just gonna compare them directly.
0:10 And here's the same code in Python,
0:12 really The only difference is where the return value goes and whether it goes int
0:16 p1_id or p1_id int.
0:18 Right, this is the same basic code.
0:21 And if you print out p1_id or p2_id,
0:24 it's gonna look just like the same thing that we had in C++,
0:28 but it's not the same thing.
0:30 In Python, these are different than what we had in C++. In
0:35 C++ they're just allocated as the program runs technically on the stack.
0:39 They're not passed by value, all sorts of stuff like that.
0:43 So we're going to see that,
0:44 actually, these also live out in memory, they're
0:47 dynamically allocated, they have to be cleaned up just like our person object was.
0:51 So these are pointing out here in just the same way. In some sense,
0:56 does Python a Pointers? Python has more pointers than almost every other language,
1:00 right? Even things like numbers and integers or functions themselves or modules and source code
1:06 all of those things are objects and pointers.
1:10 Even when they operate as basic numbers, like we have here
1:14 these are basic numbers that are allocated dynamically
1:17 out in memory.