Python · Functions: Parameters & Scope

What do the built-in globals() and locals() functions return, and how do they relate in the main program?

Answer locked. Get the free KnowCard app to reveal it — plus spaced-repetition review so it actually sticks.

Get it on App StoreGet it on Google Play

This is one card from the KnowCard library — thousands more across SAP, Linux, Python and more. In the app you get the answer, AI explanations, and cards that come back right before you would forget them. Free to start on iOS, Android or the web.

More in Functions: Parameters & Scope

What does this print? ``` def f(x, acc=[]): acc.append(x) return acc print(f(1)) print(f(2)) ```
When is a parameter's default value expression actually evaluated?
What does this print? ``` def f(a=[1, 2, 3]): a += [4, 5] print(a) f() f() ```
In a function definition, where must parameters with default values be placed, and why?
A function ends without ever executing a return statement. What does calling it evaluate to?
What does this print, and why? ``` def my_sum(a, b, c=0, d=0): return a + b + c + d print(my_sum(d=1, b=3, c=2, a=1)) ```

Start learning today

Free to start — download the app or use it in your browser.

Get it on App StoreGet it on Google Play