0
0
Goprogramming~15 mins

Importing packages in Go - Mini Project: Build & Apply

Choose your learning style9 modes available
Importing packages
📖 Scenario: You are writing a simple Go program that uses a package to print text to the screen.
🎯 Goal: Learn how to import a package and use a function from it to display a message.
📋 What You'll Learn
Create a Go file with a main package
Import the fmt package
Use fmt.Println to print a message
💡 Why This Matters
🌍 Real World
Importing packages is how Go programs use code written by others or in other files, like printing text or doing math.
💼 Career
Knowing how to import and use packages is essential for writing real Go programs in software development jobs.
Progress0 / 4 steps
1
Create the main package and function
Write the first two lines to create a Go program with package main and a func main() function.
Go
Hint

Every Go program starts with a package declaration and a main function to run.

2
Import the fmt package
Add an import statement to import the fmt package right after package main.
Go
Hint

Use import "fmt" to bring in the package for printing.

3
Use fmt.Println to print a message
Inside the main function, write fmt.Println("Hello, Go!") to print the message.
Go
Hint

Use fmt.Println to print text with a new line.

4
Run the program to see the output
Write fmt.Println("Hello, Go!") is already done. Now run the program and print the output.
Go
Hint

Running the program should print Hello, Go! to the screen.