Import is the ability to retrieve data from an application or program
For example, an application might facilitate importing contacts
In programming, import is typically a keyword used to retrieve modules or functions from a package or file
A module is a piece of code (like a set of functions, a file or directory) which can be distributed and can be independently created and maintained
In Python, modules are imported by using import
statement
A file containing Python code, for example: ncthon.py
, is called a module, and its module name is ncthon
It can be imported to another file as
import ncthon
Then, specific function of the module can be accessed using .
(dot notation) like
import ncthon
ncthon.some_function()
Above example calls a function some_function()
of ncthon module
Same function can be imported using from
keyword in the import statement or using .
(dot)
from ncthon import some_function
some_function()
Similarly, a module can be imported from a directory hierarchy using .
(dot) between directory names
To imported all global variables and objects wildcard *
import can be used
from ncthon import *
some_function()
A Java package is like a directory that contains Java classes, interfaces, enumerations etc and packages (which are typically related)
To use such a class or interface, it is typically imported using import
For example, the built-in ArrayList
class is to be imported from java.util
package
import java.util.ArrayList;
class PrintList {
public static void main(String[] args) {
ArrayList<Integer> intList = new ArrayList<>(3);
intList.add(43);
intList.add(22);
intList.add(31);
System.out.println(myList);
}
}