Why doesn’t Python have pointers? In this lesson, you’ll learn how pointers seem to go against the Zen of Python. Pointers encourage implicit changes rather than explicit ones, and they are often complex rather than simple.
Python Doesn't Have Pointers
00:00 Python does not actually support the idea of pointers. You can’t use the reference or dereference operator to obtain memory addresses or follow them. No one really knows why Python doesn’t support these.
00:47 Even worse, they beg for you to shoot yourself in the foot or do something dangerous, like read from a section of memory you weren’t supposed to. Like other higher-level languages, Python tends to abstract away from these low-level implementation details like memory management. This makes the idea of pointers kind of useless.
01:09 When you pass a variable to a function, you don’t have to worry about any real memory management. Python will make sure to free up the memory that your variables use when they’re no longer accessible, something that would normally require the use of pointers when dealing with large objects.
02:01 Even though a C program might take longer to write and is much easier to get wrong, when that code does work, it’s going to be a lot faster than its Python equivalent. Without background processes like garbage collection, C absolutely flies.
02:18 This is a trade-off you have to consider when starting a new programming project. If you’re programming something that deals a lot with hardware, like memory, such as a graphics driver or a game engine, you’ll want to use C. For anything that isn’t so performance-critical, Python is often a better choice. As you’ll learn later on, we can mix the two and get the best of both worlds.
Become a Member to join the conversation.