Python Language Unicode Encoding and decoding

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

Always encode from unicode to bytes. In this direction, you get to choose the encoding.

>>> u'🐍'.encode('utf-8')
'\xf0\x9f\x90\x8d'

The other way is to decode from bytes to unicode. In this direction, you have to know what the encoding is.

>>> b'\xf0\x9f\x90\x8d'.decode('utf-8')
u'\U0001f40d'


Got any Python Language Question?