How to compare type of an object in Python?

后端 未结 14 2483
闹比i
闹比i 2020-11-28 01:26

Basically I want to do this:

obj = \'str\'
type ( obj ) == string

I tried:

type ( obj ) == type ( string )
<
14条回答
  •  青春惊慌失措
    2020-11-28 02:05

    isinstance()
    

    In your case, isinstance("this is a string", str) will return True.

    You may also want to read this: http://www.canonical.org/~kragen/isinstance/

提交回复
热议问题