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
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.

🌐
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.
🌐
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
Master Python string encode() and decode() methods. Learn UTF-8, ASCII, Unicode handling, error handling modes, and practical encoding/decoding examples.
🌐
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 first three bytes represent the first three characters C, a, and f. These are single bytes containing the characters' ASCII codes, which each fit within a single byte. The last two bytes combined represent the last character, é. ... Do ...
🌐
Real Python
realpython.com › convert-python-bytes-to-strings
How to Convert Bytes to Strings in Python – Real Python
July 18, 2026 - When you use the urlopen() function, Python automatically returns the data as bytes, since data is transmitted in that raw format. The strings you see are simply a human-readable representation of these bytes. Create a Python file named decode_bytes.py and add the following code:
Find elsewhere
🌐
Python
docs.python.org › 3 › library › codecs.html
codecs — Codec registry and base classes
This module defines base classes for standard Python codecs (encoders and decoders) and provides access to the internal Python codec registry, which manages the codec and error handling lookup process. Most standard codecs are text encodings, which encode text to bytes (and decode bytes to ...
🌐
DataCamp
datacamp.com › tutorial › bytes-to-string-python
How to Convert Bytes to String in Python | DataCamp
June 12, 2024 - To convert bytes to strings in Python, we can use the .decode() method, specifying the appropriate encoding.
🌐
Medium
towardsdev.com › python-string-encode-decode-5f159294cd33
Python encode() and decode(). When we work with String sometimes we… | by Sunil Kumar | Towards Dev
August 1, 2022 - Encoding is a way to convert a string to a bytes object. The decoding is a way to convert a bytes object to a string. Python provides encode() and decode() functions to perform Encoding and decoding respectively .
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-strings-decode-method
Python Strings decode() method - GeeksforGeeks
May 11, 2026 - The following flowchart shows the working of Python decoding: ... Encoding converts a string into bytes and decode() brings it back to its original form.
🌐
Real Python
realpython.com › python-bytes
Bytes Objects: Handling Binary Data in Python – Real Python
March 5, 2025 - After mapping each byte value into the corresponding character with Python’s chr() function, you .join() them into the string 'Real Python'. Keep in mind that this approach only works for byte values within the ASCII range. To decipher foreign Unicode characters, which may be encoded using more than one byte, you’ll have to specify the respective character encoding: ... >>> data = [0x63, 0x61, 0x66, 0xc3, 0xa9] >>> bytes(data).decode("utf-8") 'café' >>> "".join(map(chr, data)) 'café'
🌐
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.
🌐
Code Beautify
codebeautify.org › base64-to-image-converter
Base64 to Image Decoder / Converter
Base64 to Image Decoder is the best online tool to converts base64 string into image. It's easy to use base64 image decoder which helps to decode picture and Download.
🌐
Python.org
discuss.python.org › python help
Converting bytes to string to bytes - Python Help - Discussions on Python.org
October 28, 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.
🌐
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 ... resultant string which will display “Hello World!”. ... The str() function can be used in Python to convert bytes to string....
🌐
W3Schools
w3schools.com › python › ref_func_bytes.asp
Python bytes() Function
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Practice Problems Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Training ... The bytes() function returns a bytes object.
🌐
Python
docs.python.org › 3 › library › io.html
io — Core tools for working with streams
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).
🌐
n8n
community.n8n.io › questions
How to access file bytes using Python code node? - Questions - n8n Community
April 26, 2026 - 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 geo data into a geo bundle (gpkg, and to a lesser extent gpx/geojson/…). My issue is, I don’t know how to access the binary blob data with Python, and geopandas is a Python lib.
🌐
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.