Data Types
Last updated
package main
import "fmt"
func main() {
var varByte byte = 'a' // ASCII value of 97
var varRune rune = '♥' // Unicode value of U+2665
fmt.Printf("%c = %d and %c = %U\n", varByte, varByte, varRune, varRune)
}a = 97 and ♥ = U+2665var num1 float32 = 20.0320
var num2 = 20.0818 // Type inferred as float64var num1 = 3 + 7i // Type inferred as complex128var flag = true// No newlines, and can contain escape sequences like \n, \t
var fstr="Hello World"
// Can span multiple lines. Escape characters are not allowed.
var sstr= `Hello world, this
a multi-line text string.`var i int = 42
var f float64 = float64(i)
var u uint = uint(f)// short syntax
i := 42
f := float64(i) // 42.000000
u := uint(f)package main
import "fmt"
func main() {
i := 42
f := 12.0212
c := 0.5 + 2i
fmt.Printf("i is of type %T\n", i)
fmt.Printf("f is of type %T\n", f)
fmt.Printf("c is of type %T\n", c)
}i is of type int
f is of type float64
c is of type complex128