Go Package reflect: Difference between revisions
Jump to navigation
Jump to search
(Created page with "=External= * https://golang.org/pkg/reflect/ =Internal= * Standard Library") |
No edit summary |
||
Line 1: | Line 1: | ||
=External= | =External= | ||
* https://pkg.go.dev/strconv | |||
* | =Internal= | ||
* [[Go_Language_Modularization#reflect|Standard library]] | |||
= | =Overview= | ||
=Getting the Type of Variable= | |||
<syntaxhighlight lang='go'> | |||
package main | |||
import ( | |||
"fmt" | |||
"reflect" | |||
) | |||
func main() { | |||
i := 10 | |||
f := 10.1 | |||
s := "blue" | |||
fmt.Println(reflect.TypeOf(i)) // will print 'int' | |||
fmt.Println(reflect.TypeOf(f)) // will print 'float64' | |||
fmt.Println(reflect.TypeOf(s)) // will print 'string' | |||
} | |||
</syntaxhighlight> |
Revision as of 00:54, 22 August 2023
External
Internal
Overview
Getting the Type of Variable
package main
import (
"fmt"
"reflect"
)
func main() {
i := 10
f := 10.1
s := "blue"
fmt.Println(reflect.TypeOf(i)) // will print 'int'
fmt.Println(reflect.TypeOf(f)) // will print 'float64'
fmt.Println(reflect.TypeOf(s)) // will print 'string'
}