Skip to content

Latest commit

 

History

History
21 lines (18 loc) · 329 Bytes

20220912092040.md

File metadata and controls

21 lines (18 loc) · 329 Bytes

bytes to string and vice versa

You can use decode() / encode() in Python to go from bytes to strings and vice versa:

>>> b = b"string"
>>> type(b)
<class 'bytes'>
>>> s = b.decode("utf-8")
>>> s
'string'
>>> type(s)
<class 'str'>
>>> b = s.encode("utf-8")
>>> b
b'string'
>>> type(b)
<class 'bytes'>

#strings #bytes