Skip to content
Justice Tech School

Data Types

Go is statically typed. Basic types are bool, string, integers (int, int8 to int64, uint), floats (float32, float64), byte and rune. Use a conversion such as float64(x) to change types, because Go never converts silently.

Example
var i int = 42
var f float64 = 3.5
var s string = "go"
var b bool = true
fmt.Printf("%T %T %T %T\n", i, f, s, b)
fmt.Println(float64(i)+f, int(f))
var r rune = 'A'
fmt.Println(r, string(r))

Result

int float64 string bool
45.5 3
65 A

Exercise

Convert i to a float.

f := (i)

Quiz Test

Does Go convert types automatically?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.