Namespaces & Scope | 18/100 Days of Python Algo Trading

Congratulations on reaching this stage!

If you’re here, it means you’re truly dedicated to mastering Python. Directly below, you’ll find a quiz designed to help you reinforce what you’ve just learned. This isn’t just about recalling facts; it’s about deeply understanding the concepts. Take a moment to answer the questions and see how well you can apply the knowledge from the video. You’re doing great—every question you tackle brings you one step closer to becoming a Python expert!

Day 18: Namespaces

1. What is a namespace in Python?
2. What does the LEGB rule stand for in Python?
3. In the context of the LEGB rule, what is considered a 'Local' scope?
4. Which scope would a variable belong to if it is defined at the top of a file?
5. How can you access a global variable from within a function?
6. What is true about the 'Built-in' scope?
7. How does Python resolve names using the LEGB rule when a name is referenced?
8. Which scenario would cause a NameError in Python?
9. How would you modify a global variable inside a function?
10. What does the 'Enclosing' scope refer to?
11. When does Python create a new local namespace?
12. What is the effect of the nonlocal keyword in Python?
13. Which Python statement is used to bring a variable from the global namespace into another scope?
14. What would be a common example of a 'Local' variable in algorithmic trading?
15. How can encapsulating code in a function affect variable scope?
16. What type of error results from trying to modify an enclosing scope variable inside a function without nonlocal?
17. Which statement about namespace is false?
18. In the context of LEGB, what would you define as an 'Enclosing' variable example?
19. What is not a feature of Python namespaces?
20. Which Python feature ensures that a function can access names that belong to more than one enclosing function?