Suppose you have a string in ASCII form you can encode it to utf-8 or utf-16 using encode function, please go through the below code snippet to do the same,
>>> x="String"
>>> x.encode('utf-8')
b'String'
>>> x.encode('utf-16')
b'\xff\xfeS\x00t\x00r\x00i\x00n\x00g\x00'
Hope this helps!!
If you need to learn more about Python, It's recommended to join Python Certification Training today.
Thanks!