In this tutorial, we will learn the basic syntax of Go language. We will go through the key components of a simple Go program.
package main
import "fmt"
func main() {
fmt.Println("Hello, World!")
}
Hello, World!
package main
main
is a special package name that tells the compiler this is the entry point of the program.import "fmt"
fmt
package, which contains functions for formatted I/O, including printing to the console.func main()
func
keyword is used to declare a function.{
fmt.Println("Hello, World!")
Println
function is part of the fmt
package and prints the provided text followed by a new line.}
;
), though semicolons are automatically inserted at the end of each line.//
for single-line comments or /* ... */
for multi-line comments.{}
.Main
and main
would be considered different identifiers.