Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set your subtitle preferences in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please see our video player troubleshooting guide to resolve the issue.

Pointers and Objects in Python (Overview)

If you’ve ever worked with lower-level languages like C or C++, then you may have heard of pointers. Pointers are essentially variables that hold the memory address of another variable. They allow you to create great efficiency in parts of your code but can lead to various memory management bugs.

You’ll learn about Python’s object model and see why pointers in Python don’t really exist. For the cases where you need to mimic pointer behavior, you’ll learn ways to simulate pointers in Python without managing memory.

In this course, you’ll:

  • Learn why pointers in Python don’t exist
  • Explore the difference between C variables and Python names
  • Simulate pointers in Python
  • Experiment with real pointers using ctypes


Sample Code (.zip)

5.2 KB


Course Slides (.pdf)

2.5 MB

00:00 Hi, I’m Austin Cepalia with realpython.com! And in this course, you’ll learn all about pointers and memory management in Python. Love them or hate them, pointers are essential to writing efficient code in many low-level languages.

00:16 If you’ve ever worked with C or C++ then chances are, you are no stranger to the concept of pointers. If you haven’t, though, or you’re not familiar with pointers, that’s okay too.

00:28 In the next two videos, I’ll explain all you need to know about pointers for the rest of this course.

00:35 As we go along, we’ll also be looking at a little bit of code written in C. I’ll explain exactly what this code does as if you’ve never programmed in C before, so this course really doesn’t have any prerequisites.

00:50 You’ll start by learning about why Python doesn’t actually support the idea of pointers, at least not in a traditional sense. To do that, you’ll look under the hood at variables and examine how Python manages data types, references, and memory.

01:07 Once you have a better understanding of pointers and memory management, I’ll show you some ways to simulate pointer behavior using just Python.

01:16 Finally, you’ll learn how to create real C-style pointers with the ctypes module, which will let you work with C libraries in your Python programs.

01:27 Having pointers in your programmer’s toolkit will not only allow you to see a different way of working with program data, but it will also allow you to interface your Python code with C code that requires the use of pointers.

01:42 To start, I’ll explain the basics of pointers and why they’re often needed.

Become a Member to join the conversation.