Fix the TypeError: Can Only Join an Iterable in Python

Strings, lists, tuples, and other similar objects are often referred to as iterables in Python. This is because they contain a finite number of elements that can be referred to using their indexes; we can loop over these objects using a simple for loop.
A handy function that works with such iterables is the join() function. This function can combine the elements of an iterable to a single string, and we can specify the separator of the elements in the string with the function.
This tutorial will discuss the TypeError: can only join an iterable error in Python.
Fix the TypeError: can only join an iterable in Python
Since it is a TypeError , we can conclude that an unsupported operation is being performed on a given object. This error is encountered when we try to combine the elements of an unsupported type of object using the join() function.
In the above example, we tried to use the join() function with an integer and got this error.
The fix to this error is simple, only use the valid data types that are iterable.
A very simple example of the join() function with an iterable is shown below.
Remember that since the join() function returns a string, the elements of an iterable also must be a string; otherwise, a new error will be raised.
There are some cases where we get the can only join an iterable error while working with iterables.
The above example raises the error because the reverse() function reverses the order of elements in the original list. It does not create a new list.
So, in the above example, the object b value is None. That is why the error is raised.
In such cases, be mindful of the final object passed onto the join() function. We can fix the above example using the reversed() method, which returns a new list.
See the code below.
Since the reversed() method returns a new list, the error was avoided in the above example.
Manav is a IT Professional who has a lot of experience as a core developer in many live projects. He is an avid learner who enjoys learning new things and sharing his findings whenever possible.
Вызов ''.join ведёт к ошибке: TypeError: can only join an iterable
![]()
str.join(iterable) ожидает в качестве аргумента iterable — объект поддерживающий итерирование.
iterable An object capable of returning its members one at a time. Examples of iterables include all sequence types (such as list , str , and tuple ) and some non-sequence types like dict , file objects, and objects of any classes you define with an __iter__() or __getitem__() method. Iterables can be used in a for loop and in many other places where a sequence is needed ( zip() , map() , . ). When an iterable object is passed as an argument to the built-in function iter() , it returns an iterator for the object. This iterator is good for one pass over the set of values. When using iterables, it is usually not necessary to call iter() or deal with iterator objects yourself. The for statement does that automatically for you, creating a temporary unnamed variable to hold the iterator for the duration of the loop. See also iterator, sequence, and generator.
по простому на русском (c) @jfs:
».join() принимает составной объект—коллекцию строк, такую как список, которую можно в for-цикл передать, чтобы все строки обойти
Вот один из способов определения является ли объект итерируемым и заодно примеры итерируемых объектов:
Typeerror: can only join an iterable
Are you encountering Typeerror: can only join an iterable ?
Well, joining strings can be a powerful tool in Python, allowing you to easily concatenate multiple strings into one. However, it’s important to remember that not all objects are iterable.
Apparently, this could be the reason why the error is triggered.
In this guide, we will provide you with some practical solutions and examples to solve this error and help you write error-free Python code.
Please enable JavaScript
So, let’s dive in and fix that error!
What is Typeerror: can only join an iterable?
The Python “TypeError: can only join an iterable” is an error typically occurs when we try to concatenate a string with a non-iterable object, such as an integer or a float.
Further, the join() method in python is used to join the elements of an iterable object, such as a list or a tuple, into a string.
However, this method can only be used with iterable objects, and not with non-iterable objects.
For instance, we have a list of strings and we want to join them into a single string separated by a comma.
We could use the join() method like this:
This would output the following.
blue, red, orange
However, if we try to use the join() method with a non-iterable object, such as an integer or a float, we would get the “TypeError: can only join an iterable” error message.
In the next section, you will see how this error occurs.
Example Scenario of Typeerror: can only join an iterable
Here is how this error occurs:
In this example, the variable num is an integer, which is a non-iterable object. When we try to use the join() method on num, we get a “TypeError: can only join an iterable” error.
Solutions for Typeerror: can only join an iterable
Certainly! Here are some solutions for the “TypeError: can only join an iterable” error
1. Convert the non-iterable object to an iterable object before using join()
If you are trying to join a non-iterable object, such as an integer or a float, you need to convert it to an iterable object before using the join() method.
One way to do this is to convert the object to a string using the str() function, and then split the string into individual characters or digits using the list() function.
For example:
Output:
1-0-2-0-3-0
2. Use a different method to concatenate the string and the non-iterable object.
If you are trying to concatenate a string with a non-iterable object, such as an integer or a float, you can use a different method to do so, such as string formatting or concatenation.
For example:
Output:
The number is 123
3. Check the type of the object before using join()
Before using the join() method, you can check the type of the object to make sure it is iterable.
If it is not iterable, you can use one of the other solutions listed above to convert it to an iterable object or concatenate it with a string in a different way.
For example:
Output:
42
Anyway, we also have a solution for Typeerror series objects are mutable thus they cannot be hashed errors, you might encounter.
Factors caused Python typeerror can only join an iterable
- Attempting to use join() on a non-iterable object.
- Using the wrong syntax when calling join().
- Trying to join an object that is not a string.
- Passing the wrong type of iterable to join().
- Using a non-string separator.
Conclusion
To conclude, Typeerror: can only join an iterable will occur when we try to concatenate a string with a non-iterable object, such as an integer or a float.
To fix this error, we need to convert the non-iterable object to an iterable object before using join(), or use a different method to concatenate the string and the non-iterable object
We hope this guide helped you fix your error and get back on your coding.
Python TypeError: can only join an iterable Solution
![]()
The join() method lets you transform an iterable object such as a list into a string. It is the opposite of the split() method. If you try to use this method to join a value that is not an iterable object into a list, you’ll encounter the “TypeError: can only join an iterable” error.
In this guide, we’re going to talk about what this error means and how it works. We’ll walk through an example of this list to help you learn how it works.
TypeError: can only join an iterable
Let’s take a look at our error message: TypeError: can only join an iterable.
TypeErrors are raised when you try to perform an operation on a value whose data type does not support that operation. The message after the error type tells us that we’re trying to join a value that is not an iterable object.
The join() method only lets you join iterables like a list or a tuple. This is because the join method traverses through every item in a sequence and adds them to a string. If a value is not iterable, this process cannot occur.
This error is common when you try to join a value that is equal to None.
An Example Scenario
Let’s build a program for a cheesemonger that orders a list of cheeses. We’ll ask a user whether they want the cheeses ordered in ascending or descending order. To start, let’s define a list of cheeses:
cheeses = [«Parmesan», «English Cheddar», «Feta», «Roquefort», «Brie»]
Next, we’re going to ask the user for the order in which they want the cheese list to appear:
order = input(«Do you want the cheeses to appear in ascending (ASC) or descending (DESC) order? «)
We’re going to use an “if” statement to translate the answer a user inserts into a boolean:
If a user inserts the value “ASC”, the list will be sorted in ascending order. Otherwise, the list will be sorted in reverse order.
Next, we’re going to use the sort() method to sort our list:
We refer to the “reverse” variable we defined earlier. This lets us tell the sort() method whether we want our cheeses to be sorted in ascending or descending order.
Now that we’ve sorted our cheeses, we are going to join them into a string and print them to the console:
The join() method joins all the cheeses from the “cheeses” list into a string. Each cheese will be separated by a space and a comma. We enclosed these characters in quotation marks in our code before we called the join() method.
Let’s execute our program:
Do you want the cheeses to appear in ascending (ASC) or descending (DESC) order? ASC
Our code returns an error.
The Solution
Our code asks the user for the order in which the list of cheeses should appear. Our code stops working on line 12. This is where we join our cheeses list into a string.
The problem is that the value of “cheeses” becomes equal to None in our code. This is because we’ve assigned the value of the sort() method to a new variable.
The sort() method sorts a list in-place. It alters an existing list. The sort() method does not return a new list. This means that when we assign the value of cheeses.sort(reverse=reverse) to a variable, the value of that variable becomes None.
To solve this problem, we’ve got to remove the variable declaration on the line of code where we sort our cheeses:
This code will sort our list of cheeses. The value of “cheeses” will be equal to the sorted list rather than None. Let’s run our code and see what happens:
Do you want the cheeses to appear in ascending (ASC) or descending (DESC) order? ASC

«Career Karma entered my life when I needed it most and quickly helped me match with a bootcamp. Two months after graduating, I found my dream job that aligned with my values and goals in life!»
Venus, Software Engineer at Rockbot
Find Your Bootcamp Match
Your sorted cheeses are: Brie, English Cheddar, Feta, Parmesan, Roquefort
Our code successfully returns a sorted list of cheeses. Let’s try to sort our cheeses in descending order:
Do you want the cheeses to appear in ascending (ASC) or descending (DESC) order? DESC
Your sorted cheeses are: Roquefort, Parmesan, Feta, English Cheddar, Brie
Our code is capable of sorting our lists both in ascending and descending order.
Conclusion
The “TypeError: can only join an iterable” error is caused when you try to join a value that is not iterable to a string.
This can happen if you assign the value of a built-in list method such as sort() to a new variable and try to join the result of that operation to a string. You can fix this error by ensuring that the value that you try to join into a string is an iterable, like a list or a tuple.
Now you’re ready to solve this error in your code like a professional!
About us: Career Karma is a platform designed to help job seekers find, research, and connect with job training programs to advance their careers. Learn about the CK publication.