bytes-like object code example
Example 1: bytes-like object
newstr = "Hello World"
newstr_bytes = newstr.encode("ascii")
print(newstr_bytes)
Example 2: bytes-like object
str_string = "Educative"
str_bytes = str_string.encode("ascii")
print("encdoed = ", str_bytes)
print(type(str_bytes))
print(list(str_bytes))
list_bytes = list(str_bytes)
for b in list_bytes:
print(chr(b), "is represented by",b)
str_decode = str_bytes.decode("ascii")
print("decoded = ", str_decode)
Example 3: TypeError: a bytes-like object is required, not 'str'
'Hello World'.encode()