Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
package main import ( "fmt" "math" "unicode/utf8" ) func main() { // Integer types var i int = 42 var i64 int64 = 100 // Explicit conversion required sum := i + int(i64) fmt.Println("sum:", sum) // Float operations var f float64 = math.Sqrt(2) fmt.Printf("sqrt(2) = %.6f ", f) // float64 -> int truncates (does NOT round) fmt.Println("int(f):", int(f)) // String and runes s := "Hello, 世界" fmt.Println("bytes :", len(s)) fmt.Println("runes :", utf8.RuneCountInString(s)) for i, r := range s { fmt.Printf("index=%d rune=%c code=%d ", i, r, r) } // byte slice round-trip b := []byte(s) s2 := string(b) fmt.Println("round-trip:", s2) // Boolean var flag bool = true fmt.Println("flag:", flag, "!flag:", !flag) }
Result
Open