Khalid Al-Ghamdi wrote:
Hi All,

why is this so?

type('love')
<class 'str'>
"love" is str
False


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, you want:

isinstance("love", str)

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:

http://www.canonical.org/~kragen/isinstance/



--
Steven
_______________________________________________
Tutor maillist  -  [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to