Function internals

๐Ÿ”ฅ

Function is wrapper around code object. Code object is wrapper for byte-code.

๐Ÿช„ Code:

def f1():
    return "Hello"
f2 = lambda: "Hello"

print(f1.__code__.co_code)
print(f2.__code__.co_code)

๐Ÿ“Ÿ Output:

b'd\x01S\x00'
b'd\x01S\x00'

๐Ÿช„ Code:

print(f1.__code__.__doc__)

๐Ÿ“Ÿ Output:

code(argcount, kwonlyargcount, nlocals, stacksize, flags, codestring,
      constants, names, varnames, filename, name, firstlineno,
      lnotab[, freevars[, cellvars]])

Create a code object.  Not for the faint of heart.

Last updated