KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm unclear about the difference between the syntax != and is not . They appear to do the same thing: >>> s = 'a' >>> s != 'a' False >>> s is not 'a' False But, when I use is not in a list comprehension, it produces a different result than if I use != . >>> s = "hello" >>> [c for c in s if c is not 'o'] ['h', 'e', 'l', 'l', 'o'] >>> [c for c in s if c != 'o'] ['h', 'e', 'l', 'l'] Why did the o get included in the first list, but not the second list?
Tags (comma-separated)
Save Edits
Cancel