Go Data Types and Operators
ExampleGo
package main
import "fmt"
func main() {
a, b := 17, 5
fmt.Println(a+b, a-b, a*b, a/b, a%b)
fmt.Println(float64(a) / float64(b))
fmt.Println(a > b && b > 0)
var small int8 = 127
small++ // wraps around
fmt.Println(small)
s := "héllo"
fmt.Println(len(s), len([]rune(s)))
}Output
22 12 85 3 2 3.4 true -128 6 5
Go never converts types behind your back: to divide two ints as decimals you convert them with float64(...). A string's len counts bytes, so the accented letter counts as two.
Quick check
Does Go convert int to float automatically in arithmetic?
Finish the quick check (and any code exercise) to complete this lesson, or mark it done yourself.
Tip: use the left and right arrow keys to move between lessons.