How do I see the type of a variable whether it is unsigned 32 bit, signed 16 bit, etc.?
How do I view it?
转载于:https://stackoverflow.com/questions/402504/how-to-determine-a-python-variables-type
How do I see the type of a variable whether it is unsigned 32 bit, signed 16 bit, etc.?
How do I view it?
转载于:https://stackoverflow.com/questions/402504/how-to-determine-a-python-variables-type
print type(variable_name)
I also highly recommend the IPython interactive interpreter when dealing with questions like this. It lets you type variable_name?
and will return a whole list of information about the object including the type and the doc string for the type.
e.g.
In [9]: var = 123
In [10]: var?
Type: int
Base Class: <type 'int'>
String Form: 123
Namespace: Interactive
Docstring:
int(x[, base]) -> integer
Convert a string or number to an integer, if possible. A floating point argument will be truncated towards zero (this does not include a string representation of a floating point number!) When converting a string, use the optional base. It is an error to supply a base when converting a non-string. If the argument is outside the integer range a long object will be returned instead.