Recall & Review
beginner
What is the built-in scope in Python?
The built-in scope is the area where Python's built-in functions and names like <code>print()</code>, <code>len()</code>, and <code>int()</code> live. These are always available anywhere in your code without needing to import or define them.Click to reveal answer
beginner
Where does Python look first when you use a name in your code?
Python first looks in the local scope (inside the current function or block), then in the enclosing scopes (like outer functions), then in the global scope (the main script), and finally in the built-in scope if it doesn't find the name anywhere else.
Click to reveal answer
intermediate
Can you override a built-in function name in your code? What happens?
Yes, you can create a variable or function with the same name as a built-in. This will hide the built-in inside your current scope, so when you use that name, Python uses your version instead of the built-in. This can cause confusion, so it's best to avoid it.
Click to reveal answer
beginner
Example: What will this code print?
print(len([1, 2, 3]))
It will print
3 because len() is a built-in function that returns the number of items in a list.Click to reveal answer
intermediate
How can you see all the names in the built-in scope?
You can import the <code>builtins</code> module and use <code>dir(builtins)</code> to list all built-in names available in Python.Click to reveal answer
Which scope does Python check LAST when looking for a variable name?
✗ Incorrect
Python checks the built-in scope last after local, enclosing, and global scopes.
What happens if you define a variable named
print in your code?✗ Incorrect
Your variable named
print hides the built-in function in the current scope.How can you list all built-in functions and names in Python?
✗ Incorrect
Import
builtins and use dir(builtins) to see all built-in names.Which of these is NOT a built-in function in Python?
✗ Incorrect
my_function() is not a built-in function; it's a user-defined name.If a name is not found in local, enclosing, or global scopes, what does Python do?
✗ Incorrect
Python looks in the built-in scope before raising a NameError.
Explain the order Python uses to find a variable name when you use it in your code.
Think about the LEGB rule.
You got /5 concepts.
Describe what happens if you create a variable with the same name as a built-in function.
Consider how Python decides which name to use.
You got /4 concepts.