🌐
Real Python
realpython.com › convert-python-bytes-to-strings
How to Convert Bytes to Strings in Python – Real Python
July 18, 2026 - In the example above, .decode() uses UTF-8 encoding automatically since no encoding was specified. When the code runs, it converts the raw bytes fetched from the website into a readable HTML string, which can then be displayed or parsed further. The b prefix seen in the earlier byte representation disappears, and the result becomes a standard string: ... $ python decode_bytes.py Bytes: b'<!doctype html><html lang="en"><head><title>Example Domain</title>… String: <!doctype html><html lang="en"><head><title>Example Domain</title>…
🌐
Mimo
mimo.org › glossary › python › string-decode
Python string decode(): Syntax, Usage, and Examples
To decode a byte object, call .decode() on it and pass in the encoding type. UTF-8 is the most common encoding used on the web and in most modern applications. The method also accepts an errors argument that controls how decoding errors are handled. ... Become a Python developer.
Discussions

Python 3 - Encode/Decode vs Bytes/Str - Stack Overflow
I've read some good posts, that made it all much clearer, however I see there are 2 methods on python 3, that handle encoding and decoding, and I'm not sure which one to use. So the idea in python 3 is, that every string is unicode, and can be encoded and stored in bytes, or decoded back into ... More on stackoverflow.com
🌐 stackoverflow.com
Decoding bytes
How are you decoding with utf-8? In what way does it not work? Do you have an error message? What encoding is the file actually in? More on reddit.com
🌐 r/learnpython
12
3
May 13, 2024
How to convert bytes to string in python?
Try this: line = ser.readline().strip() values = line.decode('ascii').split(',') a, b, c = [int(s) for s in values] The call to .strip() removes the trailing newline. The call .decode('ascii') converts the raw bytes to a string. .split(',') splits the string on commas. Finally the call [int(s) for s in value] is called a list comprehension, and produces a list of integers. More on reddit.com
🌐 r/Python
3
1
February 8, 2016
Why is encoding bytes to UTF-8 called decoding?
You are indeed confused: bytes.decode - encodes the bytes as UTF-8 No, it decodes a byte sequence to a string, interpreting it as an UTF-8 encoded string. Strings are a sequence of code points (or characters) in Unicode. Unicode and UTF-8 are not the same thing! UTF-8 is the most popular, but still only one of many encoding schemes for Unicode. Take the string ABCÄĀ. This is represented by the unicode code point sequence U+0041 U+0042 U+0043 U+00c4 U+0100. As you see, unicode code points are more than 8 bits, so we need a way to store them in 8-bit byte sequences. One way to do that is to use UTF-8, which turns it into the byte sequence 0x41 0x42 0x43 0xc3 0x84 0xc4 0x80. As another example, UTF-16 would encode this as 0xff 0xfe 0x00 0x41 0x00 0x42 0x00 0x43 0x00 0xc4 0x01 0x00. Notice that except for the 0xff 0xfe BOM (Byte Order Mark) at the beginning, it's simply storing the 16 bit value of the code point in sequence (code points can have more than 16 bits, so it only works this way below 32768, similar to how UTF-8 doesn't change the representation below 128). The BOM is needed to know which of the two bytes represents the most significant bits, as in, is 0x12 0x34 representing 0x1234 or 0x3412. (Some machines store 16 bit values in the first way ("big endian"), others, like x86, in the other ("little endian")) There are also other encoding schemes, for example, if every unicode code point is below 256, you can use latin-1, which will just use the lower 8 bits of the unicode code point. To summarize: bytes.decode decodes a byte sequence into a string, which is an abstract representation of code points. str.encode turns this abstract representation into a byte sequence. More on reddit.com
🌐 r/learnpython
7
21
March 30, 2022
🌐
Educative
educative.io › answers › what-is-bytesdecode-in-python
What is bytes.decode() in Python?
Line 3: We encode string, cast to byte object. Line 5: We call the decode() method with utf-8 encoding scheme and strict as error handler to transform from encoded values to a string object. Line 7: We print decoded values.
🌐
Python documentation
docs.python.org › 3 › howto › unicode.html
Unicode HOWTO — Python 3.14.7 documentation
The following examples show the differences: >>> b'\x80abc'.decode("utf-8", "strict") Traceback (most recent call last): ... UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 0: invalid start byte >>> b'\x80abc'.decode("utf-8", ...
🌐
freeCodeCamp
freecodecamp.org › news › python-bytes-to-string-how-to-convert-a-bytestring
Python Bytes to String – How to Convert a Bytestring
April 10, 2023 - In this example, we define a byte string b"hello world" and convert it to a string using the decode() method with the UTF-8 character encoding. The resulting decoded string is "hello world", which is then printed to the console.
🌐
Vultr
docs.vultr.com › python › examples › convert-bytes-to-a-string
Python Program to Convert Bytes to a String | Vultr Docs
November 27, 2024 - Decode the bytes using utf-8 encoding to handle Unicode characters. ... byte_data = b'\xc2\xa9 2021 Python' string_data = byte_data.decode('utf-8') print(string_data) Explain Code
🌐
The Python Coding Stack
thepythoncodingstack.com › the python coding stack › `bytes`: the lesser-known python built-in sequence • and understanding utf-8 encoding
`bytes`: The Lesser-Known Python Built-In Sequence • And Understanding UTF-8 Encoding
July 15, 2025 - The data bits in the first byte—shown in orange—are 00011, and the data bits from the second byte are 101001. Combining them gives 00011101001. And what's this number in decimal?
🌐
DataCamp
datacamp.com › tutorial › bytes-to-string-python
How to Convert Bytes to String in Python | DataCamp
June 12, 2024 - The first 128 UTF-8 codes match the ASCII codes, which is why the bytes object data is decoded to the string "DataCamp" in the example above. However, Unicode contains nearly 150,000 characters. UTF-8 encodes all the non-ASCII characters in Unicode using two or more bytes. ... The bytes object contains two bytes: the integers 195 and 169. Python displays the hexadecimal representation of these bytes.
Find elsewhere
🌐
w3resource
w3resource.com › python › python-bytes.php
Python Bytes, Bytearray
b'Python, bytes' Example-1: Code: #create a bytes object x = b'El ni\xc3\xb1o come camar\xc3\xb3n' print(x) Output: b'El ni\xc3\xb1o come camar\xc3\xb3n' Example-2: Code: # create a string using the decode() method of bytes.
🌐
Medium
medium.com › @vivekmcm1 › understanding-pythons-encode-and-decode-with-real-world-examples-5d2080d66f01
Understanding Python’s encode() and decode() with Real-World Examples | by Vivek | Medium
August 30, 2025 - ... text = "Hello World" byte_text ... because ASCII cannot represent it. ... Decoding is the reverse process: converting bytes back into a string....
🌐
CodeRivers
coderivers.org › blog › python-bytes-decode
Python Bytes Decode: A Comprehensive Guide - CodeRivers
February 22, 2026 - The basic syntax is: bytes_object.decode(encoding='utf - 8', errors='strict') ... This code decodes the bytes object b using the UTF - 8 encoding and stores the resulting string in s. It's crucial to specify the correct encoding when decoding bytes. If the wrong encoding is used, a ...
🌐
freeCodeCamp
freecodecamp.org › news › python-bytes-to-string-code-examples
Python Bytes to String – How to Convert a Str to Bytes and Back Again
April 16, 2024 - Using the decode() method, we converted it to a string and stored it in a string_data variable: string_data = byte_data.decode('utf-8'). When you print the characters of the string_data variable, you should get string characters instead of binary ...
🌐
Analytics Vidhya
analyticsvidhya.com › home › 3 ways to convert bytes to string in python
3 Ways to Convert Bytes to String in Python
March 26, 2025 - Here’s an example: bytes_data = b'I am a bytes string' string_data = str(bytes_data,'utf-8') print("Type Before :- ",type(bytes_data)) print(string_data) print("Type After :- ",type(string_data)) ... The codecs module in Python provides a ...
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-strings-decode-method
Python Strings decode() method - GeeksforGeeks
May 11, 2026 - For example, let's try to encode and decode a simple text message: ... s = "Geeks for Geeks" e = s.encode('utf-8') print("Encoded text:", e) print(type(e)) d = e.decode('utf-8') print(type(d)) print("Decoded text:", d) ... Return Type: Returns ...
🌐
KDnuggets
kdnuggets.com › convert-bytes-to-string-in-python-a-tutorial-for-beginners
Convert Bytes to String in Python: A Tutorial for Beginners - KDnuggets
July 15, 2024 - # Converting bytes to string string_data = codecs.decode(byte_data,'utf-8') print(string_data) ... Output >>> Hello, World! In this tutorial, we learned how to convert bytes to strings in Python while also handling different encodings and potential ...
🌐
Stack Abuse
stackabuse.com › convert-bytes-to-string-in-python
Convert Bytes to String in Python
November 27, 2020 - In this tutorial, we'll go over examples of how to convert bytes to a string in Python 2 and 3. We'll use the decode() function, str() function as well as the codecs module.
🌐
CodeRivers
coderivers.org › blog › decode-bytes-python
Decoding Bytes in Python: A Comprehensive Guide - CodeRivers
February 22, 2026 - Decoding is the reverse process, ... scheme has its own rules for representing characters as bytes. In Python, you can use the decode() method on a bytes object to convert it into a string....
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-convert-bytes-to-string-in-python
How to Convert Bytes to String in Python ? - GeeksforGeeks
In this example, we are importing a pandas library, and we will take the input dataset and apply the decode() function. ... import pandas as pd dic = {'column' : [ b'Book', b'Pen', b'Laptop', b'CPU']} data = pd.DataFrame(data=dic) x = ...
Published: July 23, 2025
🌐
Net Informations
net-informations.com › python › iq › byte.htm
How to convert bytes to string in Python?
convert bytes to string in Python convert string to bytes in Python , We can convert bytes to String using bytes class decode() instance method, So you need to decode the bytes object to produce a string.
Top answer
1 of 3
74

Neither is better than the other, they do exactly the same thing. However, using .encode() and .decode() is the more common way to do it. It is also compatible with Python 2.

2 of 3
19

To add to Lennart Regebro's answer There is even the third way that can be used:

encoded3 = str.encode(original, 'utf-8')
print(encoded3)

Anyway, it is actually exactly the same as the first approach. It may also look that the second way is a syntactic sugar for the third approach.


A programming language is a means to express abstract ideas formally, to be executed by the machine. A programming language is considered good if it contains constructs that one needs. Python is a hybrid language -- i.e. more natural and more versatile than pure OO or pure procedural languages. Sometimes functions are more appropriate than the object methods, sometimes the reverse is true. It depends on mental picture of the solved problem.

Anyway, the feature mentioned in the question is probably a by-product of the language implementation/design. In my opinion, this is a nice example that show the alternative thinking about technically the same thing.

In other words, calling an object method means thinking in terms "let the object gives me the wanted result". Calling a function as the alternative means "let the outer code processes the passed argument and extracts the wanted value".

The first approach emphasizes the ability of the object to do the task on its own, the second approach emphasizes the ability of an separate algoritm to extract the data. Sometimes, the separate code may be that much special that it is not wise to add it as a general method to the class of the object.