- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How can I convert bytes to a Python string?
You need to decode the bytes object to produce a string. This can be done using the decode function from string class that will accept then encoding you want to decode with.
my_str = b"Hello" # b means its a byte string new_str = my_str.decode('utf-8') # Decode using the utf-8 encoding print(new_str)
This will give the output −
- How can I convert a bytes array into JSON format in Python?
- How can I convert a Python tuple to string?
- Convert bytes to a string in java
- How would you convert string to bytes in Python 3?
- Convert String to UTF-8 bytes in Java
- How can I convert a Python tuple to an Array?
- How can I convert a Python Named tuple to a dictionary?
- How I can convert a Python Tuple into Dictionary?
- How can I convert string to double in C/C++?
- How can I convert Python tuple to C array?
- How can I convert Python strings into tuple?
- How can I eliminate numbers in a string in Python?
- How can I fill out a Python string with spaces?