import statement
A statement that makes code from another module or package available by name in the current file.
In more detail
In Python, import math loads a module and from math import sqrt brings one name in directly. In Java, import java.util.List lets code write List instead of the full package name, and classes in java.lang are imported automatically. Importing everything with a wildcard makes it hard to tell where names came from.
Example
import java.util.List;Related terms
- package (Java) — A named group of related Java classes, such as java.util, that also forms a folder path and a namespace for class names.
- static import — An import that brings a class's static methods into scope so they can be called without the class name, such as assertThat.
- module — A file of code whose functions, classes and variables other files can use by importing it.
- module search path — The list of folders Python searches, in order, when a program imports a module.
- package — A folder of Python modules that can be imported as a group, or a distributable bundle of Python code installed with pip.
- relative import — An import inside a package that names a sibling module with a leading dot, such as from .helpers import tidy, instead of the full package path.
Taught in
- Generics Fundamentals — Modern Java: Virtual Threads & High-Throughput Services
- The Collections Framework — Modern Java: Virtual Threads & High-Throughput Services
- What Python Is, And Where It Came From — Hands-on Python: Complete Video Course & Book
- Installing Python On A Mac — Hands-on Python: Complete Video Course & Book
- Installing Python On Linux — Hands-on Python: Complete Video Course & Book
- A Graphics Introduction — Hands-on Python: Complete Video Course & Book
- Modules And The Import System — Hands-on Python: Complete Video Course & Book
- Packages, And Your Own Library — Hands-on Python: Complete Video Course & Book
- Interpreter, Compiler, And What Counts As Syntax — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Literals, Names And Four Number Bases — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Print, Input And The Casts Between — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- The Class That Shared One List — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Sixty Five Minutes, Forty Items: How PCAP Is Run — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Import Variants, dir() And sys.path — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- math, random And platform — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Your Own Modules And Packages — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Modules Sprint — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Introspection: hasattr, __name__, __module__ And __bases__ — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Generators And Iterators — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Streams, Handles And Open Modes — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- read, readline, errno And bytearray — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Comprehensions, Closures And Files Sprint — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Twelve Traps, Mostly Objects — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Mock, Review And Exam Day — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
References
- Java Tutorials: Using Package Members
- Java Language Specification, chapter 7: Packages and Modules
- Python tutorial: modules
- Simple statements: import