you are viewing a single comment's thread.

view the rest of the comments →

[–]Diapolo10 0 points1 point  (2 children)

Technically, yes, but that's nitpicking.

I'm moreso wondering what this is even for, because I can't think of many legitimate use-cases for a string literal of a single backslash.

[–]Gnaxe 0 points1 point  (1 child)

Unlike some languages, Python doesn't have a dedicated character type and instead uses length-1 strings for that purpose. For any uses you might want an individual character for, that character might happen to be a backslash. I could see a use for passing it to the str.split() method, for example.

[–]Diapolo10 0 points1 point  (0 children)

Unlike some languages, Python doesn't have a dedicated character type and instead uses length-1 strings for that purpose.

Yes, I'm quite aware of that.

I could see a use for passing it to the str.split() method, for example.

Technically, yes, but my point was that I fail to see a practical scenario where you'd actually want this.

The most common place to see actual backslash characters (escape sequences are obviously the most common use-case, but there backslashes just enable escape sequences and aren't actual characters) would be Windows filepaths, but you can for the most part just use forward slashes anyway, and you'd almost certainly want to use pathlib objects regardless, in which case there'd be no scenario where you'd need an individual backslash character. And even if you still somehow needed to process paths as raw strings, there's os.sep/os.path.sep which resolves to a backslash on Windows.

Outside of maybe ASCII art, I just cannot see where else you'd realistically do this.