- First add the package main in your program:
package main
Every Go file must start with a package name statement. Packages provide code encapsulation and reuse. The name of the package here is main.
- After adding main package import “fmt” package in your program:
import(
"fmt"
)
Import the fmt package, which will be used to print text to the standard output in the main function.
- Now write the code in the main function to print hello world in Go language:
func main() {
fmt.Println("Hello World")
}
func main():
The main function is a special function that is the entry point of a Go program. The main function must be included in the main package. { and } denote the start and end of the main function.
fmt.Println(“Hello World”):
The Println function in the fmt package is used to print text to standard output.
Top comments (0)