Different Use Of ‘From Module Import’ and ‘Import Module’?

In this post, we will learn the Different Use of ‘import module’ or ‘From module import’ in Python as both are ways to import the module where the import module if used for importing the entire module unlike in from import, is used for importing a specific function in a given in a module. To learn more stay tuned here.


Import-Module Vs From Module Import

Here we will find the difference between them using some examples which could help in knowing better for our program to reduce the complexity and execution time.


there we have given the syntax for imports, here we will import the entire module, including all its functions, classes, and variables. When using this syntax, you must prefix any function or class calls with the module name, followed by a dot (“.”) operator. And to know better follow the example given below and implement the same to understand all of it.

As we know that we need to import the module we have to use some in built modules of python as it is so in those cases we use this method to get the module used in the existing project or programm.

import math
x = math.sqrt(4)

Here we had imported the entire module of math just to use one of its functions sqrt() which will differently increase it execution time where we could also apply some alternative to save time and memory here we are simply finding the squat root of the given value which we simply provided as per the requirements.

From Module Import

As in case of This, we could specifically import the function we actually need which simply means that we do not neet to import the entire heavy module just for executing a single function of that particular module which we can perform as we have given the example below where we can easily see how we have done this the execution could be taken below.

from math import sqrt
x = sqrt(4)

Here also we are using the same function we had used earlier from the same module but at this time we are using a different approach to import the module as instead of importing the module we are simply importing the function of that particular module which makes it precedes and faster as there is no load of importing the heavy package or module unnecessarily.



To learn more about the Different Use of ‘import module’ or ‘from module import’ visit: ┬áby stack overflow.

To learn more about solutions to different problems and tutorials for the concepts we need to know to work on programming along with different ways to solve any generally asked problems: How To Pass-Variables From A Java & Python Client To A Linux/Ubuntu Server Which Is Running C?.


Leave a Comment

%d bloggers like this: