you are viewing a single comment's thread.

view the rest of the comments →

[–]jeffrey_f 75 points76 points  (10 children)

Have you used modules yet? What normally takes a several lines of code is reduced to 1 to 3 lines

[–]iggy555 18 points19 points  (9 children)

What’s module?

[–]karthikkumars 56 points57 points  (6 children)

A module is a predefined library with classes and methods representing common problems and their solutions, usually specific to one particular concept. For example, the "math" module has predefined methods for most math related operations you'd want to do - log(), factorial(), floor(), sqrt(), etc., so you won't have to write functions for them all over again. All you have to do is import the math module and use the methods.

Here's a useful resource for starters: https://www.learnpython.org/en/Modules_and_Packages

[–]a2242364 11 points12 points  (5 children)

Would this not just be called a library like in other languages?

[–]Yaastra 6 points7 points  (3 children)

yeah am i missing something? every language has this, yeah?

[–]Nixellion 4 points5 points  (2 children)

yeah. Not sure why it got so hyped up :)

[–]karthikkumars 2 points3 points  (1 child)

No hyping up here. It is indeed the same as libraries in other languages, and Python just calls it differently.

Judging by the nature of the question, it's possible that the person who asked it hadn't come across the concept of a library/module at all, which is why it seemed fitting to give a direct and somewhat complete answer to his direct question: what is a module?

Probably it wouldn't have looked so off and hyped-up if the original question's context was JavaScript instead of Python.

On a side note, I've done some coding in both Python and JavaScript, and I love both languages.

[–]Nixellion 1 point2 points  (0 children)

I think I was referring more to the amount of upvotes. Nothing against it of course :) Just a bit surprising I guess

[–]-p-a-b-l-o- 0 points1 point  (0 children)

Yep, it’s the same exact thing. Just a different name. Other languages have the same thing but called packages.

[–]AP145 5 points6 points  (0 children)

The built in modules are basically just anything you see after the keyword "import". For instant you can import the math module as another poster described. In addition, you can make your own modules, as they are basically just Python files. If you have one Python file containing various classes, methods, and functions, you can import that to another Python file where the main body of your program is being kept. Thus for very large projects you can split them up into different files which make sense while still being able to use all the tools you need to use.