Function Dissection Lab - Learn How Functions Work
Offered By: PyCon US via YouTube
Course Description
Overview
Explore the inner workings of Python functions in this insightful talk from PyCon US. Dive deep into function attributes, understanding how Python manages arguments, distinguishes between variable scopes, and handles special features like *args and **kwargs. Examine the relationship between function attributes, Python bytecodes, and function behavior. Gain a deeper appreciation for the object-oriented nature of Python functions and how their attributes contribute to their functionality. Learn about error messages, additional variables, constants, default arguments, keyword-only arguments, and scoping rules. Investigate the LEGB (Local, Enclosing, Global, Built-in) rule and its implementation in Python. Enhance your Python programming skills by understanding the underlying mechanisms of function execution and variable resolution.
Syllabus
Intro
I teach Python
Consider this code
Function objects? . When you use def. you create a function object.
Example
Error messages use this info
Additional variables
So, how does Python know?
Same goes for **kwargs
dis.show_code
Constants?
When Python calls a function...
Consider this function
Let's add a default
Keyword-only arguments
Where does Python put that?
Let's talk about scoping
How does Python know x isn't local?
Let's make things more complex
A more common version of this problem
The "global" declaration
Bytecodes with a local"X"
Putting the "E" in LEGB
What have we learned?
Questions or comments?
Taught by
PyCon US
Related Courses
Intro to Python for Brand New ProgrammersPyCon US via YouTube Comprehending Comprehensions
PyCon US via YouTube Data Analysis with SQLite and Python
PyCon US via YouTube Build a Production Ready GraphQL API Using Python
PyCon US via YouTube Web Development With A Python-backed Frontend - Featuring HTMX and Tailwind
PyCon US via YouTube