Hatena::Groupvim

値の型の判定

値の型の判定

type()を使う。

                                                        *type()*
type({expr})    The result is a Number, depending on the type of {expr}:
                        Number:     0
                        String:     1
                        Funcref:    2
                        List:       3
                        Dictionary: 4
                To avoid the magic numbers it should be used this way: >
                        :if type(myvar) == type(0)
                        :if type(myvar) == type("")
                        :if type(myvar) == type(function("tr"))
                        :if type(myvar) == type([])
                        :if type(myvar) == type({})