How would you convert string to bytes in Python 3?

PythonServer Side ProgrammingProgramming

To convert string to bytes in Python 3, you can use the encode() function from the string class. For example,

>>> s = u"HellΘ WΘrld"
>>> s.encode('utf-8')
'Hell\xce\x98 W\xce\x98rld'
raja
Updated on 30-Sep-2019 07:19:27

Advertisements