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
Published on 13-Dec-2017 18:57:32
Advertisements