Additional meanings for "in" operator and ability to customize implementation
Note that I'm new to this system, so I'm not sure if this will format correctly or whether I'll be able to edit it afterward to format it properly if not. Fingers crossed. Examples: import re from collections import Sequence # Equivalent of re.compile(r'b.d').search(<str>) re.compile(r'b.d') in 'abcdef' # -> <_sre.SRE_Match object; span=(1, 4), match='bcd'> re.compile(r'b.d') in 'xyz' # -> None # Equivalent of isinstance([1, 2], Sequence) [1, 2] in Sequence # -> True class BrightColorsMeta(type): def __rin__(self, other): other.startswith('bright ') class BrightColors(metaclass=BrightColorsMeta): pass 'red' in BrightColors # -> False 'bright blue' in BrightColors # -> True
participants (12)
-
Andrew Barnert
-
Antoine Rozo
-
Chris Angelico
-
David Mertz
-
Ethan Furman
-
Oscar Benjamin
-
Random832
-
Rhodri James
-
Richard Musil
-
Stephen J. Turnbull
-
Steve Jorgensen
-
Steven D'Aprano