On Tue, Jun 10, 2014 at 2:14 AM, Steven D'Aprano <[email protected]> wrote: >> This is very Pythonic, Python is strictly typed language. There's no way >> None could possibly be "inside" a string, > > Then `None in some_string` could immediately return False, instead of > raising an exception.
Note, by the way, that CPython does have some optimizations that immediately return False. If you ask if a 16-bit string is in an 8-bit string, eg "\u1234" in "asdf", it knows instantly that it cannot possibly be, and it just returns false. The "None in string" check is different, and deliberately so. I do prefer the thrown error. Some things make absolutely no sense, and even if it's technically valid to say "No, the integer 61 is not in the string 'asdf'", it's likely to be helpful to someone who thinks that characters and integers are equivalent. You'll get an exception immediately, instead of trying to figure out why it's returning False. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
