Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Answer

added 137 characters in body
Source Link
MarianD
  • 14.4k
  • 12
  • 50
  • 62

Inside bytes literals you may use 2 methods2 methods for specifying individual bytes:

  1. a direct ASCII character, e. g. b'xyz', or
  2. an escape sequencessequence (starting with \), e.g. b'\n123円\x56\\'

Of course, you may combine both methods in one bytes literalsliteral, e. g. b'xy\n\x56abc'

So your b'\x6b\x0a' and b'6b0a' a both the valid bytes strings,literals - but unfortunately different:.

(The first one is 2 bytes long while the second represents 4 bytes.)

  • the 1st one consists of 2 bytes (represented as escape sequences \x6b and \x0a)
  • the 2nd one consists of 4 bytes (represented as ASCII characters 6, b, 0, and a).

Inside bytes literals you may use 2 methods for specifying individual bytes:

  1. direct ASCII character, e. g. b'xyz', or
  2. escape sequences (starting with \), e.g. b'\n123円\x56\\'

Of course, you may combine both methods in bytes literals, e. g. b'xy\n\x56abc'

So your b'\x6b\x0a' and b'6b0a' a both the valid bytes strings, but unfortunately different.

(The first one is 2 bytes long while the second represents 4 bytes.)

Inside bytes literals you may use 2 methods for specifying individual bytes:

  1. a direct ASCII character, e. g. b'xyz', or
  2. an escape sequence (starting with \), e.g. b'\n123円\x56\\'

Of course, you may combine both methods in one bytes literal, e. g. b'xy\n\x56abc'

So your b'\x6b\x0a' and b'6b0a' a both the valid bytes literals - but unfortunately different:

  • the 1st one consists of 2 bytes (represented as escape sequences \x6b and \x0a)
  • the 2nd one consists of 4 bytes (represented as ASCII characters 6, b, 0, and a).
Source Link
MarianD
  • 14.4k
  • 12
  • 50
  • 62

Inside bytes literals you may use 2 methods for specifying individual bytes:

  1. direct ASCII character, e. g. b'xyz', or
  2. escape sequences (starting with \), e.g. b'\n123円\x56\\'

Of course, you may combine both methods in bytes literals, e. g. b'xy\n\x56abc'

So your b'\x6b\x0a' and b'6b0a' a both the valid bytes strings, but unfortunately different.

(The first one is 2 bytes long while the second represents 4 bytes.)

lang-py

AltStyle によって変換されたページ (->オリジナル) /