K
K
Killir Vanya2292021-11-27 17:27:16
Python
Killir Vanya229, 2021-11-27 17:27:16

Is it important to have few imports in the code?

And is it true that if there are fewer imports, is it faster to run the code?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2021-11-27
@VEYREN

You need to have exactly as many imports as your code needs. Obviously, if you don't import the library you're using, then the code won't run. Obviously it makes no sense to import something that is not used.
Yes, it's true that imports affect startup speed. Each imported script must be read from disk, parsed, interpreted, objects of data loaded from it must be created in memory, etc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question