TypeError: sequence item 0 expected str instance (Fix)
This error usually appears when you use str.join() on a list or other sequence that contains at least one non-string value.
join() only works with strings. If your data contains integers, None, floats, booleans, or other types, Python raises a TypeError.
The good news is that this is usually easy to fix:
- find the non-string values
- convert them to strings
- or remove values that should not be joined
Quick fix
items = ["a", 1, "b"]
result = " ".join(map(str, items))
print(result)
Output:
a 1 b
Use this when you want to join mixed values into one string. It converts every item to a string first.
What this error means
This error usually happens with the join() string method.
For example, Python may show:
TypeError: sequence item 0: expected str instance, int found
This means:
- you called
join() - Python checked the items in the sequence
- one of the items was not a string
- Python stopped at the first bad item it found
If the message says item 0, the first item was the problem. If it says item 2, the third item was the first invalid value Python found.
Example that causes the error
numbers = [1, 2, 3]
result = "-".join(numbers)
print(result)
This raises:
TypeError: sequence item 0: expected str instance, int found
Why?
"-"is a string separator- but the list items are integers
join()does not convert values automatically
If you want to combine numbers as text, you must convert them first.
Why it happens
The separator in join() is a string, but the items being joined must also be strings.
Common values that cause this error are:
intfloatNoneboolbyteslist
Beginners often see this error when:
- reading data from a file
- building a list in a loop
- mixing labels and numbers in one list
- joining dictionary values
- working with user input and calculated values together
Fix 1: Convert all items to strings
The simplest fix is to convert every item to a string before joining.
items = ["apple", 10, "banana", 3.5]
result = ", ".join(map(str, items))
print(result)
Output:
apple, 10, banana, 3.5
map(str, items) applies the str() function to each item.
Use this when:
- your sequence contains mixed types
- you want every value shown as text
- you want a short and clean fix
Fix 2: Use a list comprehension
A list comprehension does the same job, but gives you more control.
items = ["apple", 10, "banana", 3.5]
result = ", ".join([str(x) for x in items])
print(result)
Output:
apple, 10, banana, 3.5
This is useful when you want to clean or format values during conversion.
For example, you can add custom formatting:
items = ["Total", 25, None]
result = " | ".join(
["missing" if x is None else str(x) for x in items]
)
print(result)
Output:
Total | 25 | missing
If you are new to this, see also how to join strings in Python.
Fix 3: Remove or replace None values
None is a very common cause of this error.
Remove None values
Use this if None should be skipped:
items = ["a", None, "b", None, "c"]
result = " ".join(str(x) for x in items if x is not None)
print(result)
Output:
a b c
Replace None with an empty string
Use this if you want to keep the position but not show text:
items = ["a", None, "b"]
result = " ".join("" if x is None else str(x) for x in items)
print(result)
Output:
a b
Replace None with a label
Use this if None has meaning in your data:
items = ["name", None, "done"]
result = " | ".join("N/A" if x is None else str(x) for x in items)
print(result)
Output:
name | N/A | done
If None appears because your code expected a list but got something else, you may also run into TypeError: 'NoneType' object is not iterable.
Fix 4: Check your data before joining
Sometimes the bad value comes from user input, a file, API data, or a loop. In that case, inspect the sequence before calling join().
Useful debugging lines:
items = ["a", 1, None, ["x"]]
print(items)
print(type(items))
print([type(x) for x in items])
print(repr(items))
Possible output:
['a', 1, None, ['x']]
<class 'list'>
[<class 'str'>, <class 'int'>, <class 'NoneType'>, <class 'list'>]
['a', 1, None, ['x']]
These checks help you see:
- whether
itemsis really a list - what types are inside it
- whether a nested list or
Noneis present
If needed, use the type() function to inspect values one by one.
Common situations where beginners see this
Here are some common examples.
Joining numbers into CSV-style text
numbers = [10, 20, 30]
csv_line = ",".join(map(str, numbers))
print(csv_line)
Output:
10,20,30
Joining dictionary values that are not all strings
data = {"name": "Ana", "age": 25}
result = " - ".join(str(value) for value in data.values())
print(result)
Output:
Ana - 25
Joining file path parts with numbers mixed in
parts = ["user", 42, "report.txt"]
path = "/".join(map(str, parts))
print(path)
Output:
user/42/report.txt
Joining a list built from input and calculations
name = "Sam"
score = 95
items = ["Name:", name, "Score:", score]
result = " ".join(map(str, items))
print(result)
Output:
Name: Sam Score: 95
Related errors
This error is closely related to other string conversion problems.
You may also see:
- TypeError: can only concatenate str (not "int") to str
- TypeError: 'NoneType' object is not iterable
ValueErrorwhen converting text to numbersAttributeErrorwhen calling string methods on non-strings
FAQ
Why does the error say sequence item 0?
It means the first item Python checked was not a string. The number may change if a later item is the first invalid one.
Does join() convert integers to strings automatically?
No. You must convert each item yourself before calling join().
Should I use map(str, items) or a list comprehension?
Both work.
map(str, items)is shorter- a list comprehension is better when you also want to filter, replace, or format values
What if my list contains None values?
Either remove None values or replace them before joining.