Python Bytes

#218 Keyboards for developers, Python, and some history

Informações:

Sinopsis

Sponsored by Datadog: pythonbytes.fm/datadog Special guest: Jeremy Tanner Watch on YouTube Brian #1: Constant Folding in Python Arpit Bhayani Constant Folding is when a language replaces constant expressions at compile time rather than computing them at runtime. CPython does this while creating the bytecode. We can use dis to see it in action >>> import dis >>> dis.dis("day_sec = 24 * 60 * 60") 1 0 LOAD_CONST 0 (86400) 2 STORE_NAME 0 (day_sec) 4 LOAD_CONST 1 (None) 6 RETURN_VALUE Python tries to fold lots of constants, but not all. Seems to be based on size >>> x = 2 ** 64 # folded >>> x = 4 ** 64 # not folded >>> a = "-" * 4096 # folded >>> a = "-" * 4097 # not folded Discussion continues with a discussion of how CPython folding is implemented recursively and elegantly. Key takeaway for me: Remember to n