Pythonで型を調べる…type, types

Pythonで型を調べる件
>> type("moji")

type()はtypeオブジェクトを返してくる。 標準型のtypeはパッケージtypesに定数として定義されている。

typeオブジェクトを比較してみるSample

#!/usr/bin/env python
# coding: utf-8

from types import *

a = "moji"

if type(a) is StringType:
 print u"それはstringですね"

if type(a) is ListType:
 print u"それはlistですね"

結果

それはstringですね

コメント

このブログの人気の投稿

nginxでlocalhostとしてアクセスをサーバーに転送する方法

Android・・・テキスト描画あれこれ, ascent(), descent()等

Android:stateに応じて切り替わるdrawable・・・StateListDrawable