3 ms·
`encode` converts text to an encoded form. `decode` converts an encoded form to text. This was confusing in Python 2 because you could encode bytes into… more b
by minitech 10y ago
`encode` converts text to an encoded form. `decode` converts an encoded form to text. This was confusing in Python 2 because you could encode bytes into… more bytes. What? Python 3 only lets you encode text and decode bytes, as it should, and removes the confusion.
- forgottenacc57 10y agoYeah that explanation really ironed out any confusion.
- minitech 10y agoI think you’d probably get used to it after using it a couple of times/being familiar with what the types represent. Text is a sequence of characters, but you can encode it into a sequence of bytes when necessary. Give it a try! Also, it’s probably worth mentioning that you rarely need to use `encode` or `decode` in Python 3. Most text can just stay text. If you make a mistake, the stronger types are there to help you notice it.