31
loading...
This website collects cookies to deliver better user experience
bytes(str, enc, error)
#Using the byte() method
# initializing string
str_1 = "Join our freelance network"
str_1_encoded = bytes(str_1,'UTF-8')
#printing the encode string
print(str_1_encoded)
#printing individual bytes
for bytes in str_1_encoded:
print(bytes, end = ' ')
b'Join our freelance network'
74 111 105 110 32 111 117 114 32 102 114 101 101 108 97 110 99 101 32 110 101 116 119 111 114 107
string.encode(encoding=encoding, errors=errors)
#Using the encode method
# initializing string
str_1 = "Join our freelance network"
str_1_encoded = str_1.encode(encoding = 'UTF-8')
#printing the encode string
print(str_1_encoded)
#printing individual bytes
for bytes in str_1_encoded:
print(bytes, end = ' ')
b'Join our freelance network'
74 111 105 110 32 111 117 114 32 102 114 101 101 108 97 110 99 101 32 110 101 116 119 111 114 107
encode()
method, the decode()
method can be used to convert bytes to strings.#Using the encode method
#initializing string
str_1 = "Join our freelance network"
str_1_encoded = str_1.encode(encoding = 'UTF-8')
#printing the encode string
print(str_1_encoded)
#decoding the string
str_1_decoded = str_1_encoded.decode()
print(str_1_decoded)
b'Join our freelance network'
Join our freelance network