FAQ: Modules: Python - Modules Python Namespaces

I’m still not clear, why we just import some modules and include the “from …” for others?

like in the exercise:

import codecademylib3_seaborn

from matplotlib import pyplot as plt

import random

I went a bit too fast through the explanation, so I didn’t really understand what to do here. However, I tried with pre-existing knowledge from loops, and to my surprise it worked on first try.

numbers_b = []
for i in range(12):
  numbers_b.append(random.randint(1,1000))

Obviously, not as elegant and short as using random.sample, but nice to see that green tick mark regardless of approach.

1 Like

When we use ‘import module_name’, to call a function of the module, we type module_name.function_name().

What about ‘import module_name from object_name’? Should it be module.name.function() or object_name()?

The plt.show,is basically a tool that shows in a 2D dimention what you made in your cade, for example like if you were projecting. Lets say you just made this code!: numbers_ = range(1, 13) which was said it had to be inclusive. Here is an explaniation of what inclusive means in python: We could do this pretty easily: my_list = range(51) … the word “inclusive” means that the value 50 should be included in the range . So, the ending value of the range is set to 51 (exclusive) in the Python statement, meaning that 51 is not included in the range. So, yes that numbers_ = range(1, 13) it is the (X) axis and the other (Y) axis it is the random.sample(range(1000), 12).
So both of this sintax will be plot on your screen whenever you use the tool plt.plot = create the graphic 2D
and plt.show basically print the graphic 2D in your screen

Hope this help is just how I understand it!.

Well basically just to use what we want to use from the module and not the whole module arg or fuctions etc.
for example from matplotlib we are going to be using just pyplot but with the name of plt