Thuta Learning
BasicProgrammingbeginner

Syntax & Hello World

Relax. We'll talk through this in plain words — no textbook voice.

Go's syntax is designed to be simple and readable. You usually don't need to write semicolons yourself, but you should still be careful with line breaks. To start a program, you can generally think of it as package main, import section, func main().

go
package main

import "fmt"

func main() {
    message := "Go syntax is clean."
    fmt.Println(message)
}

message := "..." creates a variable using short assignment. The Go compiler looks at the value and automatically infers the type.

You should see
Go syntax is clean.

Info

{ on the same line as the function declaration matters in Go style. The Go formatter gofmt can clean up your code style to keep it consistent.

Easy traps

  • In Go, declaring a variable and never using it causes an error. If you're just testing something, use it with fmt.Println(variable).