Class Central is learner-supported. When you buy through links on our site, we may earn an affiliate commission.

YouTube

Function Dissection Lab - Learn How Functions Work

PyCon US via YouTube

Overview

Save Big on Coursera Plus. 7,000+ courses at $160 off. Limited Time Only!
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

Reviews

Start your review of Function Dissection Lab - Learn How Functions Work

Never Stop Learning.

Get personalized course recommendations, track subjects and courses with reminders, and more.

Someone learning on their laptop while sitting on the floor.