Foundations Updated 2026-09 View as Markdown

Variables

A variable is a name given to a storage area that the programs can manipulate.

A variable is a name given to a storage area that the programs can manipulate. The name of a variable can be composed of letters, digits, and the underscore character. It must begin with either a letter or an underscore.

Numbers#

They are arithmetic types and they represents following values throughout the program. a) integer types b) floating point

To define an integer, use the following syntax:

go
var a int = 4
var b, c int
b = 5
c = 10
fmt.Println(a)
fmt.Println(b + c)

To define a floating point number, you may use one of the following notations:

go
var d float64 = 9.14
fmt.Println(d)

Strings#

Strings in Go are defined with double quotes.

go
var s string = "This is string s"
fmt.Println(s)

The difference between the two is that using double quotes makes it easy to include apostrophes (whereas these would terminate the string if using single quotes)

go
var s string = "Don't worry about apostrophes"
fmt.Println(s)

Shorthand Declaration#

The := notation serves both as a declaration and as initialization. foo := "bar" is equivalent to var foo string = "bar"

go
a := 9
b := "golang"
c := 4.17
d := false
e := "Hello"
f := `Do you like golang, so far?`
g := 'M'

fmt.Println(a)
fmt.Println(b)
fmt.Println(c)
fmt.Println(d)
fmt.Println(e)
fmt.Println(f)
fmt.Println(g)
Exercise

Try it

run this one locally

Expected output

John Doe
24
154.61

Get the Go agent pack

A battle-tested AGENTS.md, the review checklist, and the failure-mode cheat sheet for Go. One email, then occasional updates when the tooling shifts. No course pitch.

Unsubscribe in one click. We never sell the list. Or just take the AGENTS.md now — no email needed.