如何在 Python 3 中將字串轉換為位元組?
要將字串轉換到 Python 3 中的位元組,可使用字串類的 encode() 函式。例如:
>>> s = u"HellΘ WΘrld" >>> s.encode('utf-8') 'Hell\xce\x98 W\xce\x98rld'
廣告
要將字串轉換到 Python 3 中的位元組,可使用字串類的 encode() 函式。例如:
>>> s = u"HellΘ WΘrld" >>> s.encode('utf-8') 'Hell\xce\x98 W\xce\x98rld'