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.

Answer from Lennart Regebro on Stack Overflow
🌐
Python documentation
docs.python.org › 3 › library › stdtypes.html
Built-in Types — Python 3.14.4 documentation
When formatting a number (int, float, complex, decimal.Decimal and subclasses) with the n type (ex: '{:n}'.format(1234)), the function temporarily sets the LC_CTYPE locale to the LC_NUMERIC locale to decode decimal_point and thousands_sep fields of localeconv() if they are non-ASCII or longer than 1 byte, and the LC_NUMERIC locale is different than the LC_CTYPE locale.
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.

Discussions

Converting bytes to string to bytes
How can I convert bytes to string to bytes back? Here’s what I’m trying: from cryptography.hazmat.primitives import hashes from cryptography.hazmat.primitives.asymmetric import padding message = b"A message I want to sign" signature = private_key.sign( message, padding.PSS( mgf=padding... More on discuss.python.org
🌐 discuss.python.org
8
0
October 27, 2021
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
🌐
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 - How do you convert bytes to string? A. You can convert bytes to a string using .decode('utf-8') in Python, which decodes the byte object into a human-readable string using UTF-8 encoding.
🌐
Educative
educative.io › answers › what-is-bytesdecode-in-python
What is bytes.decode() in Python?
bytes.decode() is used to decode bytes to a string object. Decoding to a string object depends on the specified arguments. It also allows us to mention an error handling scheme to use for seconding errors.
🌐
DigitalOcean
digitalocean.com › community › tutorials › python-string-encode-decode
Python String Encode and Decode: Complete Guide | DigitalOcean
August 3, 2022 - Please enter string data: aåb∫cçd∂e´´´ƒg©1¡ Encoded bytes = b'a\xc3\xa5b\xe2\x88\xabc\xc3\xa7d\xe2\x88\x82e\xc2\xb4\xc2\xb4\xc2\xb4\xc6\x92g\xc2\xa91\xc2\xa1' Decoded String = aåb∫cçd∂e´´´ƒg©1¡ str_original equals str_decoded = True · You can checkout complete python script and more Python examples from our GitHub Repository.
🌐
Replit
replit.com › home › discover › how to convert bytes to a string in python
How to convert bytes to a string in Python | Replit
February 24, 2026 - This isn't a human-readable string yet; it's the computer's representation of the data. To translate this into text, you use the .decode('utf-8') method. Specifying the encoding—in this case, 'utf-8'—is essential.
Find elsewhere
🌐
The Python Coding Stack
thepythoncodingstack.com › p › bytes-python-built-in-unicode-utf-8-encoding
`bytes`: The Lesser-Known Python Built-In Sequence • And Understanding UTF-8 Encoding
June 1, 2024 - 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? ... Here's a list of some of the Unicode characters. If you look up the character with a decimal value of 233, you'll find it's the character é. You can also find the character corresponding to a Unicode value directly in Python:
🌐
Python.org
discuss.python.org › python help
Converting bytes to string to bytes - Python Help - Discussions on Python.org
October 27, 2021 - How can I convert bytes to string to bytes back? Here’s what I’m trying: from cryptography.hazmat.primitives import hashes from cryptography.hazmat.primitives.asymmetric import padding message = b"A message I want to sign" signature = private_key.sign( message, padding.PSS( mgf=padding.MGF1(hashes.SHA256()), salt_length=padding.PSS.MAX_LENGTH ), hashes.SHA256() ) converting the signature using base64 encode and decode methods to string.
🌐
Real Python
realpython.com › convert-python-bytes-to-strings
How to Convert Bytes to Strings in Python – Real Python
October 5, 2025 - 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.
🌐
W3Schools
w3schools.com › python › ref_func_bytes.asp
Python bytes() Function
Python Examples Python Compiler ... Study Plan Python Interview Q&A Python Bootcamp Python Training ... The bytes() function returns a bytes object....
🌐
n8n
community.n8n.io › questions
How to access file bytes using Python code node? - Questions - n8n Community
2 weeks ago - Hi. I’m on n8n 2.16.1, self-hosted, with docker, docker runners with geopandas installed. I am pulling data from 3 Baserow tables (buildings, entrances, documents). I am making a compound JSON and I am pre-fetching all files. Then, I want to use a Python node to use geopandas to export my ...
🌐
Reddit
reddit.com › r/learnpython › decoding bytes
r/learnpython on Reddit: Decoding bytes
May 13, 2024 -

I am receiving these bytes from by calling s3 url(https://<bucketname>s3.regionname.amazonaws.com/test.txt)

Response: b’\x15\x03\x01\x00\x02\x01\x00’

I really cant make sense of it. Decoding with uft-8 doesnt work. Same for utf16. Can someone help me make sense of it. How can this be decoded into something meaningful.

🌐
Python
docs.python.org › 3 › library › io.html
io — Core tools for working with streams
January 30, 2026 - The TextIOBase ABC extends IOBase. It deals with streams whose bytes represent text, and handles encoding and decoding to and from strings. TextIOWrapper, which extends TextIOBase, is a buffered text interface to a buffered raw stream (BufferedIOBase).
🌐
Pierian Training
pieriantraining.com › home › how to convert a string to bytes using python
Understanding String and Bytes Conversions in Python
April 27, 2023 - In the above code, we define a variable named binary_data and assign it some binary data represented by the prefix b. Then, we call the decode() method on this variable and pass “utf-8” as its argument which specifies that our byte sequence ...
🌐
Python
bugs.python.org › issue40863
Issue 40863: bytes.decode changes/destroys line endings on windows - Python tracker
June 4, 2020 - This issue tracker has been migrated to GitHub, and is currently read-only. For more information, see the GitHub FAQs in the Python's Developer Guide · This issue has been migrated to GitHub: https://github.com/python/cpython/issues/85040
🌐
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.
🌐
TutorialsPoint
tutorialspoint.com › article › how-can-i-convert-bytes-to-a-python-string
How can I convert bytes to a Python string?
March 24, 2026 - The decode() method is the most straightforward approach for converting bytes to strings. Use str() when you need to explicitly specify encoding, and codecs.decode() for advanced encoding scenarios.
🌐
Online Tools
emn178.github.io › online-tools › base64_decode.html
Base64 Decode - Online Tools
This online Base64 decoding tool helps you decode Base64 to text or binary. You can output UTF-8, UTF-16, Hex, or other encodings. It also supports various formats such as RFC 4648 (standard and URL Safe), RFC 2045 (MIME), RFC 2152 (UTF-7), ...
🌐
Flexiple
flexiple.com › python › bytes-to-string
Python Bytes to String – How to Convert a Bytestring - Flexiple
February 23, 2024 - To convert bytes to a string, Python uses the decode method. This method applies a specific encoding to transform bytes into a string.