As the title says, is there a way to get the internal data type of a variable in Python 3?
In C# I can compare it as follows:
var str = "Strings";
if (str.GetType() == typeof(string))
Debug.WriteLine("str es un string.");
But I can't find a way to do it in python.
Yes, instead of
typeof
istype
:Edit: In python 3 it returns
class
instead oftype
but I guess that doesn't affect in this case:As in C#, in python we talk about types and classes interchangeably. The difference is that in python there is multiple inheritance and asking for the type of an object is somewhat ambiguous.
The correct way to check the type of an object is to use
isinstance
(equivalent tois
C#):