Scope vs Namespace

In Python, scope and namespace go hand in hand. Think of scope as the area in your code where a name can be seen. So, when we talk about Python scopes, we're basically talking about where names are visible in your program.


Behind the scenes, Python makes use of dictionaries to keep track of these names and their associated objects. These dictionaries are often referred to as namespaces. In simpler terms, a namespace is like a container that holds names and their corresponding things.


So, when you hear about Python scopes and namespaces, just remember: scope tells you where a name is visible, and namespace is the behind-the-scenes dictionary that keeps track of these names in different parts of your code."

Post a Comment

Previous Post Next Post