PythonStringencode

Encodes the string to bytes using the specified encoding.

Syntax

str.encode(encoding, errors?)

Example

Enter values below to update the example in real time.

encoded
encode
print
text = "안녕"
encoded = text.encode("utf-8")
print(encoded)  # b'\xec\x95\x88\xeb\x85\x95'
print(encoded.decode("utf-8"))  # 안녕