3 ms·
Python's mechanism for this is using a single-character prefix, which would still be needed even if it followed the Ruby/PHP syntax -- simply because Python has
by BerislavLopac 7y ago
Python's mechanism for this is using a single-character prefix, which would still be needed even if it followed the Ruby/PHP syntax -- simply because Python has at least four different types of string literals:
* f"f-strings", which do both substitution and escaping
* regular "strings", which do escaping but no substitution
* r"r-strings" (for "raw"), which do neither
* b"b-strings", which are actually not strings but sequences of bytes
- pansa2 7y agoThere are also `fr`-prefixed strings, which do substitution but no escaping, and `br`-prefixed raw byte sequences.
- BerislavLopac 7y agoExcellent point, thank you! There are also the u"u-strings" which were reintroduced to reduce the workload when converting the Python 2 programs; unfortunately they forgot to do the same for the relatively common (at least when defining regular expressions) ru"ru-strings" and ur"ur-strings"...