# Introduction to the Python Interpreter, Part 3: Understanding Bytecode

DevFeed: [Introduction to the Python Interpreter, Part 3: Understanding Bytecode](<https://devfeed.tech/articles/introduction-to-the-python-interpreter-part-3-understanding-bytecode-29436.md>)

Original publisher: [Read original article](<http://akaptur.github.com/blog/2013/11/17/introduction-to-the-python-interpreter-3/>)

Published: 2013-11-17T17:56:00Z

Content type: tutorial

Language: en

Sources: [Allison Kaptur](<https://devfeed.tech/sources/allison-kaptur.md>)

Topics: [Python](<https://devfeed.tech/topics/python.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [bytecode](<https://devfeed.tech/tags/bytecode.md>), [code](<https://devfeed.tech/tags/code.md>), [internals](<https://devfeed.tech/tags/internals.md>), [python](<https://devfeed.tech/tags/python.md>)

## AI overview

Part 3 of a series on the Python interpreter explains that Python bytecode is a sequence of bytes stored in a code object's co_code attribute. It introduces disassembly with Python's dis module as a way to inspect this intermediate interpreter state.

## Source excerpt

[Edit: A significantly expanded version of this series appears as a chapter in The Architecture of Open Source Applications, volume 4, as A Python Interpreter Written in Python.] This is Part 3 in a series on the Python interpreter. Part 1 here, Part 2 here. If you're enjoying this series, consider applying to Hacker School, where I work as a facilitator. Bytecode When we left our heroes, they had come across some odd-looking output: 1 2 >>> foo.func_code.co_code 'd\x01\x00}\x01\x00|\x01\x00|\x00\x00\x17S' This is python bytecode. You recall from Part 2 that "python bytecode" and "a python code object" are not the same thing: the bytecode is an attribute of the code object, among many other attributes. Bytecode is found in the co_code attribute of the code object, and contains instructions for the interpreter. So what is bytecode? Well, it's just a series of bytes. They look wacky when we print them because some bytes are printable and others aren't, so let's take the ord of each byte to see that they're just numbers. 1 2 >>> [ord(b) for b in foo.func_code.co_code] [100, 1, 0, 125, 1, 0, 124, 1, 0, 124, 0, 0, 23, 83] Here are the bytes that make up python bytecode. The interpreter will loop through each byte, look up what it should do for each one, and then do that thing. Notice that the bytecode itself doesn't include any python objects, or references to objects, or anything like that. One way to understand python bytecode would be to find the CPython interpreter file (it's ceval.c), and flip through it looking up what 100 means, then 1, then 0, and so on. We'll do this later in the series! For now, there's a simpler way: the dis module. Disassembling bytecode Disassembling bytecode means taking this series of bytes and printing out something we humans can understand. It's not a step in python execution; the dis module just helps us understand an intermediate state of python internals. I can't think of a reason why you'd ever want to use dis in production code - it