Modules Python Namespaces: What is a namespace and in the code below which one is being renamed as plt?

from matplotlib import pyplot as plt

Is matplotlib (the module) or pyplot (the object) being renamed as plt? Also, what’s a namespace?

https://www.codecademy.com/courses/learn-python-3/lessons/modules-python/exercises/modules-python-intro

It is pyplot that is given the alias, plt.

1 Like

Also what is a namespace?

A namespace describes where variables and modules reside. Each scope is its own namespace. I could be wrong but I believe even modules are their own namespace.

1 Like

Oh that makes sense and by scope are you referring to global variables or variables inside a function, etc.?

Yes. Each block has its own scope.

1 Like