Ben Chuanlong Du's Blog

It is never too late to learn.

String vs Bytecode in Python

Comments

  1. Be careful that some functions return bytecode instead of string in Python 3.

  2. bytecode has similar APIs to str. Most string functions can be applied to bytecode as well.

String to Bytecode

In [1]:
"abc".encode()
Out[1]:
b'abc'

ByteCode to String

In [3]:
b"abc".decode()
Out[3]:
'abc'

Comments