Golangで型情報を調べる

reflect.TypeOfで

package main

import (
	"fmt"
	"reflect"
)

func main() {

	fmt.Println(reflect.TypeOf(1))          // int
	fmt.Println(reflect.TypeOf(""))         // string
	fmt.Println(reflect.TypeOf([]string{})) // []string
	fmt.Println(reflect.TypeOf(true))       // bool
	fmt.Println(reflect.TypeOf(func() {}))  // func()

}


python

# coding=utf-8

print type(0)  # <type 'int'>
print type("")  # <type 'str'>
print type(u"")  # <type 'unicode'>
print type([])  # <type 'list'>
print type(True)  # <type 'bool'>
print type(lambda e: e)  # <type 'function'>


ruby

p 1.class  # FixNum
p "".class  # String
p [].class  # Array
p true.class  # TrueClass
p lambda{}.class  # Proc