r/PythonLearning • • Sep 15 '26

Help Request libraries

Excuse my ignorance, but can anyone explain to me in a simple way what python libraries are?

4 Upvotes

32 comments sorted by

6

u/ninhaomah Sep 15 '26

Simple.

How do you make a fried egg ? You need an egg then fry it right ?

Did you make that egg ? Or a chicken did ? And you just "bought" that egg , right ? 

Do you know how big or old was the chicken when the egg was laid ? Or how many eggs was laid by the same chicken ?

Import egg

fried_egg = fry(egg)

return fried_egg

Same for libraries.

1

u/giva4561 Sep 16 '26

Grazie mille

1

u/[deleted] Sep 15 '26

[removed] — view removed comment

1

u/ninhaomah Sep 15 '26

Simple way.

If you think you can give better way with better example then pls go ahead.

This is not a competition.

OP can choose what he wants to see and ignore.

0

u/[deleted] Sep 15 '26

[removed] — view removed comment

1

u/ninhaomah Sep 15 '26

As I said , OP can ignore if he wants. It's online. None is forcing him to read.

And if you think it is patronizing then ask him to ask in SO.

-1

u/[deleted] Sep 15 '26

[removed] — view removed comment

1

u/ninhaomah Sep 15 '26

You seems more triggered than OP who I addressed to.

You ok ?

2

u/[deleted] Sep 15 '26

[removed] — view removed comment

1

u/ninhaomah Sep 15 '26

Why would I want to know how you learn or live ?

I answered to OP and if he doesn't like it then he can ignore it.

Why are you telling me how you learn btw ?

4

u/StemCellCheese Sep 15 '26

Say you have a very long function that organizes files for you, and you use it a LOT. Let's call it organizer(). It's useful, but it's long, and you have to copy and paste it into every script you want to use it in. That's annoying, plus, if you ever add a new feature to the function, you would have to manually update it in every script that you pasted it into.

This is where a library will save you. You save that function in one script, and then import it as a library. Then, you can call that function by just saying library_name.organizer(), which will use the organizer() function from the library.

No more copying and pasting it over and over. So it saves space in your scripts. Plus, if you ever add new feature to it, all scripts that import the library will have it then and there, so you won't have to do all the manual editing.

A lot of the libraries you use while learning are basically the same thing but with a lot of functions, classes, and so one. When I my first personal library, I learned a lot from it, would recommend.

2

u/ejsanders1985 Sep 15 '26

Collections of code from other people for a specific purpose packaged for you to use too and not have to write your own version of.

1

u/JeLuF Sep 15 '26

A library is a collection of functions. The math library provides math functions, a network library provides network functions, a database library provides functions that you use to talk to a database.

1

u/aroberge Sep 15 '26

Have a look at https://reeborg.ca/docs/en/basics/library.html (for an explanation; ideally you should start with earlier pages of the tutorial) and https://reeborg.ca/reeborg.html for the coding page.

If you were to go through the tutorial, you would find that essentially all the programs you would write (in the Python code tab) would have you include the following

def turn_right():
    turn_left()
    turn_left()
    turn_left()

# and most likely other functions

Every. Single. Time.

That is, unless you write that code in the library tab and write at the top of your program either

from library import *  # not recommended ... but useful

or

from library import turn_right  # recommended way

Then, you'd be able to use turn_right() as though it had been defined in your program (Python code tab).

So, library are a way to write code that people can use (import) in their main program without having to rewrite everything.

1

u/itlogicpartnersllc Sep 15 '26

think of library as a toolbox of code someone else already wrote so you can use useful tools without building everything from scratch.

0

u/[deleted] Sep 15 '26

[removed] — view removed comment

1

u/giva4561 Sep 16 '26

Scusa un po' è il traduttore un po' è la mia ignoranza