type of simple object

Jacek Generowicz jacek.generowicz at cern.ch
Tue Feb 1 06:58:48 EST 2005


"ajikoe at gmail.com" <ajikoe at gmail.com> writes:

> The result <type 'str'>
> How can I check it since it is not a string right?

It is a type, which is a first-class object in its own right.

    type('hello') == str

However, I reiterate, you almost certainly don't really care about
what the actual type is. To care about the actual type is to struggle
against a fundamental feature of python: Duck Typing.

Yes, I admit, there are situations in which you might really care
about the actual type. However, given that you do not know how to
check the type in Python, the chances are rather high that you are
sufficienly new to Python to not realize that, typically, you need not
(and should not) care about the actual type. The chances are that you
are trying to program in a style which you learned in another
language, and which not the most productive in Python.



More information about the Python-list mailing list