1

In Python 3 there are str and bytes types. To convert a bytes type into a str type, one would call the decode() method on an instance and vice versa. I am confused as to why this is, why is it not encode()? As I understand it, internally the actual bytes in memory are being encoded into an encoding (UTF-8 in Python's case).

2

1 Answer 1

4

The bytes are the encoding. You need to decode them in order to get the text they encode. How Python encodes the text as bytes internally is... not your problem.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.