Python 103: Memory Model & Best Practices

wesley chun (Google)
Location: D136 Level: Intermediate
Average rating: ****.
(4.81, 21 ratings)
Slides:   1-PDF 

In Python 101, you learned basic Python syntax. In Python 102 (or equivalent in experience), you went further, exploring Python more deeply, creating/using classes, methods, functions, decorators, files, modules/packages, and basically no longer a beginner. Because Python has been around the block for quite awhile now, there is a continuously growing number of existing “Python 103” programmers out there. Many are no longer new to the language, however, they have run into various issues, bugs, or odd behavior in their code that is difficult to explain. It’s time to take a closer look at Python. Think about questions like these:

  1. Do you know what functional evaluation strategy means? Have you been asked or considered whether Python is “call-by-value” or “call-by-reference”? It is important to you, and can you clearly explain your answer?
  1. What does “mutability” mean? What is the difference between mutable and immutable objects? Which Python objects are mutable and which aren’t?
  1. Have you seen odd behavior in container objects like lists or dictionaries? Have you ever copied objects like those and discovered weird things happening to both the original and the copy?
  1. Want to document your code better, but don’t have time and don’t find comments particularly useful? Like the concept of testing but have (sheepishly) not explored how to create unit tests?
  1. Can you clearly explain both the output in the two code snippets below, and even more importantly, why the output is the way it is?

x = 42
y = x
x += 1
print x
print y

x = [1, 2, 3]
y = x
x0 = 4
print x
print y

This talk is primarily focused on discussing at an in-depth level, how Python’s object model and memory management works. We’ll also look at best practices such as thinking about performance, “useful” commenting, and other related topics. Time-permitting, we will have a “town hall” Q&A session where attendees bring up their issues and let the audience chime in with possible solutions.

Knowing more about how the interpreter works under the covers, including the relationship between data objects and memory management, will make you a much more effective Python programmer, and the (main) goal with the knowledge imparted in this talk is to empower developers to not (inadvertently) create certain classes of bugs in their code to begin with! All you need to bring is the desire to learn more about the interpreter to take your Python skills to the next level.

Photo of wesley chun

wesley chun


+WESLEY CHUN, MSCS, is author of Prentice Hall’s bestselling “Core Python” series (, the “Python Fundamentals” companion videos, co-author of “Python Web Development with Django” (, and has written for Linux Journal, CNET, and InformIT. In addition to being a Developer Advocate at Google, he runs CyberWeb (, a consultancy specializing in Python training. Wesley has over 25 years of programming, teaching, and writing experience, including more than a decade of Python. Wesley has held engineering positions at Sun, Cisco/Ironport, HP, Rockwell, and while at Yahoo!, helped create Yahoo!Mail using Python. He has delivered courses at VMware, Hitachi, LBNL, UC Santa Barbara, UC Santa Cruz, Foothill College, and makes frequent appearances on the conference circuit. Wesley holds degrees in Computer Science, Mathematics, and Music from the University of California.


Sponsorship Opportunities

For information on exhibition and sponsorship opportunities at the conference, contact Sharon Cordesse at (707) 827-7065 or

Contact Us

View a complete list of OSCON contacts