Importing modules

I am wondering why for some modules such as random all we need to do is import random but with others like datetime why we need to do this long line from datetime import datetime

Sometimes you can import the whole module or, only the parts (functions, etc) that you need, by using the keyword “from” rather than the whole thing. Ex: the math library is huge and sometimes (most times) you wouldn’t want to import the whole thing.

2 Likes

I think the docs has a decent introduction for using modules: 6. Modules — Python 3.10.1 documentation

1 Like