When you import modules, you can choose whether to import two modules or from, and I wonder what the difference is.
The code itself doesn't change anyway, but I want to know which of the two is more advantageous.(e.g. faster module calls)
Or is it just for shortening the command code?
import time
time.sleep(10)
from time import sleep
sleep(10)
Experiments have shown that module calls do not speed up
I think it's only used to shorten the command code
I think it's the speed difference of import.
From ~ import ~ is a command to import only a specific module portion of the library, and import is a function to just import the entire library.
If you are simply trying to write sleep, there will be little difference in speed whether you import the time library or from sleep. However, when you need to create multiple classes or create another library from one library, importing functions that you don't need can slow you down, so you can import only the parts that are needed for optimization.
© 2024 OneMinuteCode. All rights reserved.