To print "Hello, world!" in Go, you can use the fmt
package which provides a convenient way to handle input and output operations. Here's the Hello World program in Go:
main.go77 chars8 lines
Here's how the above program works:
package main
tells Go that this is an executable program, rather than a library.import "fmt"
imports the fmt
package, which contains functions for printing formatted output and reading input.func main
is the entry point of the program. It's the function that gets executed when you run the program.fmt.Println("Hello, world!")
prints "Hello, world!" to the console. Println
adds a newline character at the end of the string so that the next output will appear on the next line of the console.To run this program, save it to a file with a .go
extension, and then run go run <filename.go>
in the terminal. The output should be "Hello, world!" printed to the console.
gistlibby LogSnag