Exploring code objects
main guard

Put the parts of your code that are the ones calling for execution behind a if __name__ == "__main__": guard

if __name__ == "__main__":
    def my_add(a, b):
        first = a
        second = b

        return first + second
    print_co_obj_fields(my_add.__code__)


This way you can import this python module from other places if you ever want to

Documentation

There is a python convention (docstring) to document the behaviour of a method: PEP-257

def print_co_obj_fields(code_obj):
    """prints all the instance variables of the code object that start with 'co_'"""


Indentation

To decrease the levels of indentation, you can reverse the test of startswith, and continue when it fails:

def print_co_obj_fields(code_obj):
    # Iterating through all instance attributes
    # and calling all having the 'co_' prefix
    for name in dir(code_obj):
        if not name.startswith('co_'):
            continue
        co_field = getattr(code_obj, name)
        print(f'{name:&lt;20} = {co_field}')


An alternative if using the builtin filter:

def print_co_obj_fields(code_obj):
    # Iterating through all instance attributes
    # and calling all having the 'co_' prefix
    for name in filter(lambda field: field.startswith("co_"), dir(code_obj)):
        co_field = getattr(code_obj, name)
        print(f'{name:&lt;20} = {co_field}')


Presentation

Separate the generation of the results from the presentation. The easiest way to do this is to have print_co_obj_fields yield the name and co_field instead of printing them

def co_obj_fields(code_obj):
    """generator that yields the fields in a code_object and their value"""
    for name in filter(lambda field: field.startswith("co_"), dir(code_obj)):
        co_field = getattr(code_obj, name)
        yield name, co_field

def print_co_obj_fields(fields):
    for name, co_field in fields:
        print(f"{name:&lt;20} = {co_field}")


The main part then changes to:

if __name__ == "__main__":

    def my_add(a, b):
        first = a
        second = b

        return first + second

    fields = co_obj_fields(my_add.__code__)
    print_co_obj_fields(fields)