DEV Community

Cover image for Hello World in Golang
Neeraj Kumar
Neeraj Kumar

Posted on

1 1 1

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)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay