Hello World
Go, commonly referred to as Golang, is an open-source programming language developed by a team at Google. Go is designed to be efficient, concise, and easy to use, with a focus on simplicity and productivity.
Let's start with the classic "Hello World" example.
package main
import "fmt"
func main() {
fmt.Println("Hello World")
}
You can run it directlly on the Literank online playground, or save this code in a file with a .go
extension, for example, hello.go
. You can then run it using the following command in your terminal:
go run hello.go
Imports
import "fmt"
In Go, the import
statement is used to include external packages in your code. The fmt
package is one of the standard libraries in Go, and it stands for "format." It provides functions for formatting input and output, especially for printing to the console.
Comments
Single-line comments start with //
and continue until the end of the line. Anything written after //
on a line is treated as a comment.
Multi-line comments are enclosed between /*
and */
.
// This is a single-line comment
/*
This is a multi-line comment
It can span multiple lines
Useful for longer explanations or comments
*/
Code Challenge
Try to modify the code in the editor to make it print
Hello, I'm a Gopher now.
.
Note: The Go programming language's mascot is a gopher.