Hello World in Golang

package main

import "fmt"

func main() {
    fmt.Println("Hello, World!")
}

In this program:

  1. We start with the package declaration package main, which indicates that this is the main package and serves as the entry point of the program.
  2. We import the required package fmt, which stands for “format,” and it provides functions for formatted input and output.
  3. In the main function, we use fmt.Println() to print the string “Hello, World!” to the console.

To run this Go program, follow these steps:

  1. Save the code in a file named hello.go (or any other name with the .go extension).
  2. Open a terminal or command prompt.
  3. Navigate to the directory where you saved the hello.go file.
  4. Run the following command:
go run hello.go

If everything is set up correctly, you will see the output:

Hello, World!

That’s it! You’ve just written and executed your first Go program. Congratulations!