Reputation: 21
I have a code line
emp_id=1
tp = type(emp_id)
print(tp)
print(type(tp))
strg = str(tp)
print(strg)
print(type(strg))
The result is as below
<class 'int'>
<class 'type'>
<class 'int'>
<class 'str'>
**What i need is i want to store in a string.
How to do it? **
Upvotes: 1
Views: 2399
Reputation: 20705
The function type(x)
returns the class of which the object x
is an instance. All classes in python have the property __name__
which returns the actual name (as a string) of that class.
x = 1
tp = type(x).__name__
print(tp)
This will print: int
Upvotes: 5