Reputation: 7530
I always write code like:
str(type(a)).find('int') != -1
Or
t = str(type(a)).split("'")[1]
Is there any simple way to do that?
Upvotes: 2
Views: 85
Reputation: 474191
Looks like you are asking about isinstance()
:
>>> a = 1
>>> isinstance(a, int)
True
>>> s = "test"
>>> isinstance(s, str)
True
Speaking about the the second example (string type), it is important to note that there is a basestring
type:
Upvotes: 6
Reputation: 114035
isinstance(a, int)
Example:
In [4]: a = 5
In [5]: isinstance(a, int)
Out[5]: True
Upvotes: 2