.encode python

string = 'pythön!'

print('The string is:', string)

string_utf = string.encode("utf-8")

print('The encoded version is:', string_utf)

# Output:
The string is: pythön!
The encoded version is: b'pyth\xc3\xb6n!'

# From: https://www.programiz.com/python-programming/methods/string/encode

Here is what the above code is Doing:
1. We created a string variable and assigned a value.
2. We encoded the string into bytes using the encode() method.
3. We printed the encoded string.

The output shows that the string was encoded successfully into bytes.

Note: The encode() method returns the encoded version of the string as a bytes object.