If X = "ABCD"
then encoding the X should show: \x41\x42\x43\x44
But why does X.encoding("utf-8")
shows: b"ABCD"
I am having difficulties in understanding how text encoding works in python?
If X = "ABCD"
then encoding the X should show: \x41\x42\x43\x44
But why does X.encoding("utf-8")
shows: b"ABCD"
I am having difficulties in understanding how text encoding works in python?
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