A literal string type for Python
A literal string type for Python
Posted Apr 19, 2022 4:58 UTC (Tue) by NYKevin (subscriber, #129325)In reply to: A literal string type for Python by tialaramex
Parent article: A literal string type for Python
Looking through Appendix C of the PEP (which lists the operations supported), I see removeprefix/removesuffix, but not slicing (__getitem__), so you would have to write something like s.removeprefix("DO NOT ") to get the outcome which you describe (i.e. you *can't* write s[:7] or something like that). If you explicitly write removeprefix("DO NOT "), then IMHO it's your own damn fault for removing a prefix which you apparently wanted to keep.
