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).
Anand S Kumar
91.5k18 gold badges196 silver badges179 bronze badges
1 Answer 1
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.
answered Jun 18, 2015 at 4:49
Ignacio Vazquez-Abrams
804k160 gold badges1.4k silver badges1.4k bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-py
strtype in Python3)