Getting the type of a variable

Here in this post I am going to show you some example of getting the type of the variable: From the following tests I have done you will definitely get the way how we can get the type of the variable. The common way is to use type(variable_name) which result in <type 'type_of_variable'> now if you want to get the 'type_of_variable' only then you would have to use type(variable_name).__name__.


>>> a=3.42
>>> type(a)
<type 'float'>
>>> type(a).__name__
'float'
>>> class Book:
...     name=''
...     author=''
...
>>> b=Book()
>>> type(b)
<type 'instance'>
>>> b
<__main__.Book instance at 0xb767d58c>
>>> type(b)
<type 'instance'>
>>> type(Book)
<type 'classobj'>
>>> type(Book())
<type 'instance'>
>>> type(Book).__name__
'classobj'
>>> type(Book()).__name__
'instance'
>>>

Comments

Post a Comment

Popular posts from this blog

Automate file upload in Selenium IDE

How To Install and Configure Nextcloud