[Tutor] why is this so?
steve at pearwood.info
Sun Sep 18 14:46:51 CEST 2011
Khalid Al-Ghamdi wrote:
> Hi All,
> why is this so?
> <class 'str'>
>>>> "love" is str
The "is" operator tests for object identity. The line
"love" is str
tests whether the instance "love" is the same object as the class str.
Obviously that is not the case.
You might be thinking of an "is-a" test: "love" is a string? For that,
which returns True. (That's better than type("love") is str, since it
will work for subclasses as well.)
But before getting too used to isinstance, you should read this article:
More information about the Tutor