Ask coding questions

← Back to all posts
How to modules? In python
YvngBashit (17)

So I have been learning python and what interests me the most are modules. But the problem is I don't know how to use them?

JoshDaBosh (82)

You would need to import them. For example, to use the time module, you'd do:

and you could use it's functions like time.time(), time.sleep(), etc etc

ash15khng (729)

Modules are basically allowing code from other files being used in another file. For example: import time imports the time module, allowing all of the functions in time to be used. To use a function from a module when you import a module as import modulename, use modulename.functionname(arg1, arg2="abcdefg")

DeadWither (2)

Modules are files which contain special functions that Python does not compile. When importing a module, you enable the editor to compile the functions in the module.

I am going to import the module random

But this only imports common functions. To import them all, you do this:

The * means everything.
Now when importing a module, you import lots of functions which takes more storage data. If you want to use a specific one, you can only import that. For example I want to import a function (randint, which chooses a random number), I do this:

You can use it to do fun stuff

michael2008 (0)

On a Python or JavaScript repl, you can search for a package to install by clicking on the icon on the sidebar in the workspace. Simply search for the package you want and select it to install the package or to view its documentation. Clicking on the Add Package icon will put it in a spec file and a lock file.