25 Feb
2020
25 Feb
'20
10:56 a.m.
Steven D'Aprano wrote:
On Sun, Feb 23, 2020 at 11:25:12PM +0200, Alex Hall wrote:
"Strings are not iterable - you cannot loop over them or treat them as a collection. Are you implying that we should deprecate the in operator for strings too?
I would not get rid of the `in` behavior, but the `in` behavior of a string is actually not like that of the `in` operator for a typical collection. Seen as simply a collection of single-character strings, "b" would be in "abcd", but "bc" would not. The `in` operator for strings is checking whether the left operand is a substring as opposed to an item. `(2, 3)` is not `in` `(1, 2, 3, 4)`.