Escape sequences in Python strings
Escape sequences in Python strings
Posted Aug 9, 2019 3:59 UTC (Fri) by da4089 (subscriber, #1195)In reply to: Escape sequences in Python strings by flussence
Parent article: Escape sequences in Python strings
Regardless of the convenience of "'" or '"', the mental load of choosing a quote type for every string is real: I'm frequently looking at the rest of the file to check what the usual convention is in this specific code, or going back and converting a bunch of literals that I've written using the wrong quotes.
As an unrepentant C programmer, I'm inclined to use single quotes for characters and doubles for strings, and that just creates even more pain.
Maybe deprecating one or the other could be a Python4 feature? /jk, kinda
Posted Aug 10, 2019 0:47 UTC (Sat)
by mina86 (guest, #68442)
[Link] (3 responses)
If you're willing to tolerate minor cognitive load, use double quotes if string contains single but not double quotes.
Finally, since Python doesn't have a character type, distinguishing between them and longer strings is counterproductive. Python is not C is not Algol.
Posted Aug 12, 2019 14:02 UTC (Mon)
by Bluehorn (subscriber, #17484)
[Link] (2 responses)
On an american keyboard, maybe. On a german qwertz keyboard, the double quote is above the digit 2 in the top row and the single quote is next to the big enter key. Which of course has (or maybe had) a different form on many keyboards which is why I prefer to use double quotes wherever possible.
Things are seldom simple in IT :-(
Greetings, Torsten
Posted Aug 12, 2019 14:19 UTC (Mon)
by mina86 (guest, #68442)
[Link]
I’m using Programmer Dvorak anyway which has ‘ü’ easily accessible and that’s pretty much all German characters I need to type. ;)
Posted Aug 12, 2019 14:43 UTC (Mon)
by mbunkus (subscriber, #87248)
[Link]
If all you've ever done is using an English layout, count yourself lucky. A lot of us international users have it quite a bit harder.
Escape sequences in Python strings
Escape sequences in Python strings
Escape sequences in Python strings
Escape sequences in Python strings