Hacker News new | past | comments | ask | show | jobs | submit login

CPython compiles to bytecode, turning all local variable references into offsets into a local variable array. So, getting the "str" function requires a global name lookup, while getting your local "lstr" only requires an array lookup with a constant embedded in the bytecode.

You can have a lot of fun playing with the dis module to look at the bytecode that Python generates for your functions:

http://docs.python.org/library/dis.html




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: