On 2017-04-13, Enrico Forestieri wrote: > On Thu, Apr 13, 2017 at 09:48:00AM +0100, José Abílio Matos wrote: >> On Wednesday, 12 April 2017 19.40.32 WEST Enrico Forestieri wrote: >> > I have some difficulty understanding how backslashes are treated >> > in bytes-like objects, though.
>> Do you have an examples? >> I am not aware of any differences regarding backslashes in strings or bytes. ... > So, b'\s' and r'\s' are equivalent, but b'\\s' and r'\\s' are not. > Instead, b'\\\\s' is equivalent to r'\\s'. Ther difference in backslash handling is due to the "r" praefix, not depending on binary or not: rb'\n' <-> r'\n' b'\n' <-> '\n' > The rule I infer from the above is that in b'' objects the backslash > is not special unless followed by another backslash, in which case > is quotes the backslash. This seems nonsense to me. In Python, the backslash can be used for some replacements like \n - newline, \t tab, \\ backslash ... In non-defined combinations (like \s) the backslash is kept and "\s" == "\\s". Günter