Import Functionality

This lesson introduces a basic component of Go program, i.e., packages.

Packages

A library, module, or namespace in any other language is called a package. Packages are a way to structure code. A program is constructed as a package which may use facilities from other packages. A package is often abbreviated as ‘pkg’.

Every Go file belongs to only one package whereas one package can comprise many different Go files. Hence, the filename(s) and the package name are generally not the same. The package to which the code-file belongs must be indicated on the first line. A package name is written in lowercase letters. For example, if your code-file belongs to a package called main, do the following:

Get hands-on with 1200+ tech skills courses.