How to encode a string to UTF-8 in Python

2 Answers

0 votes
s = "Python åäö"

es = s.encode()

print(es)


'''
run:

b'Python \xc3\xa5\xc3\xa4\xc3\xb6'

'''

 



answered Dec 20, 2018 by avibootz
0 votes
s = "Python åäö"

es = s.encode(encoding="UTF-8")

print(es)


'''
run:

b'Python \xc3\xa5\xc3\xa4\xc3\xb6'

'''

 



answered Dec 20, 2018 by avibootz
...