So I’m a new programmer and starting to use Python 3, and I see some videos of people teaching the language and use “import”. My question is how they know what to import and where you can see all the things you can import. I used import math in one example that I followed along with, but I see other videos of people using import JSON or import random, and I’m curious how they find what they can import and how they know what it will do.
-
pypi.org - A list of all available 3rd party Python packages that one can importbhaskarc– bhaskarc2019-11-16 05:01:14 +00:00Commented Nov 16, 2019 at 5:01
-
For a brief introduction to the concept of importing, take a look at this page of the official Python tutorial.jirassimok– jirassimok2019-11-16 05:10:27 +00:00Commented Nov 16, 2019 at 5:10
-
it's just exactly like asking, how do people know how to find the right automobile for transportation ? . well, they evaluate the situation and will get the answer to be either sedan car, cross-over car, airplane , or etc and they will find out which one to use.user12206273– user122062732019-11-16 05:47:02 +00:00Commented Nov 16, 2019 at 5:47
3 Answers
Generally, you look in the python standard library reference, or on the Python Package Index for a module that contains methods you want to use. Then you import them.
A module in python is essentially a way of doing namespaces, same as most other languages. Generally, googling "how to do ______ in python" will provide some result of someone using the module you're aiming for. Then you can look up the documentation for that module to determine what functions and classes it provides (or alternatively, import modulename the module in a python console and then do help(modulename).
3 Comments
as a starting point, the list of all python's built-in modules can be viewed here, along with documentation for each:
https://docs.python.org/3/py-modindex.html
non built-ins are usually downloaded via pip and are available here:
documentation is your friend
edit:
as stated in another comment, there is a vast amount of information at these resources..generally doing some kind of web search (google/stack/etc.) will point you towards a module you are looking for for your specific usage, then look at the examples given or check the docs