1. 程式人生 > >python中位元組與字串的轉換

python中位元組與字串的轉換

#bytes object
    byte = b"byte example"     # str object
    str = "str example"     # str to bytes 字串轉位元組
    bytes(str, encoding="utf8")     # bytes to str  位元組轉字串
    str(bytes, encoding="utf-8")     # an alternative method
    # str to bytes  字串轉為位元組
    str.encode(str)     # bytes to str  位元組轉為字串
    bytes.decode(bytes)