Communities for your favorite technologies. Explore all Collectives
Ask questions, find answers and collaborate at work with Stack Overflow for Teams.
Ask questions, find answers and collaborate at work with Stack Overflow for Teams. Explore Teams
Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
If X = "ABCD" then encoding the X should show: \x41\x42\x43\x44
X = "ABCD"
\x41\x42\x43\x44
But why does X.encoding("utf-8") shows: b"ABCD"
X.encoding("utf-8")
b"ABCD"
I am having difficulties in understanding how text encoding works in python?
\x41
A
b'\x41' == b'A'
True
bytes
ABCD
Those are the same thing - bytes are just shown in human-readable form whenever it's possible. :)
Try it yourself in Python console:
>>> b"\x41\x42\x43\x44" b'ABCD' >>> "ABCD".encode() == b"\x41\x42\x43\x44" True
Add a comment
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
\x41and printAfor you.b'\x41' == b'A'will beTrue. And that's because, again, they're the same - you're just seeing a representation of\x41.bytesare shown as user-friendly as possible. But both\x41\x42\x43\x44andABCDare just two different representations of the same information.