DEV Community

Cover image for Hello World in Golang
Neeraj Kumar
Neeraj Kumar

Posted on

Hello World in Golang

#go
  • First add the package main in your program:
package main
Enter fullscreen mode Exit fullscreen mode

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"
)
Enter fullscreen mode Exit fullscreen mode

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") 
}
Enter fullscreen mode Exit fullscreen mode

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)