Skip to main content

How to Join Strings in Python with + (Plus)

· 3 min read
Jagdish Kumawat
Founder @ Dewiride

The simplest way to join two pieces of text in Python is +: "Bike" + "shop" gives "Bikeshop". Add a space or a line break as a string of its own, and convert numbers to text first. This guide joins a few strings on Python 3.15.2.

Syntax​

Syntax
<joined> = <string 1> + <string 2>
PartWhat it means
<string 1>, <string 2>Two strings. Both sides must be text
+Joins them: the second goes straight after the first, with nothing in between

Python's built-in types reference lists s + t as "the concatenation of s and t".

The Example​

The script joins Bike and shop with a space between them, then joins two lines with a line break.

Prerequisites​

  • uv and Python 3. This guide uses uv 0.13.10 with Python 3.15.2, in a project made with uv init.

Step 1: Write the Script​

join_strings.py
first = "Bike"
second = "shop"

print(first + " " + second)
print("Line one" + "\n" + "Line two")

The join_strings.py script in a macOS-style code window: first = "Bike", second = "shop", print(first + " " + second), and print("Line one" + "\n" + "Line two").

Step 2: Run It​

Terminal
uv run python join_strings.py
Output
Bike shop
Line one
Line two

The terminal after uv run python join_strings.py: Bike shop, then Line one and Line two on two lines.

The space between Bike and shop came from the " " in the middle; + adds nothing by itself. "\n" joined the two lines with a line break. The command works unchanged in PowerShell.

Common Mistakes​

MistakeWhat happensDo this instead
Adding a number to text: "Gears: " + 7TypeError: can only concatenate str (not "int") to strConvert it first: "Gears: " + str(7) printed Gears: 7
Expecting + to add a space"Bike" + "shop" gives BikeshopAdd the space yourself: "Bike" + " " + "shop"

Troubleshooting​

SymptomLikely causeFix
can only concatenate str (not "int") to strOne side of + is a numberWrap the number in str()
Words run togetherNo space between the piecesAdd " " between them

FAQ​

Is + the only way?​

No. An f-string, such as f"{first} {second}", puts values into text without +, and converts numbers for you.

Does + change the original strings?​

No. The reference says "Strings are immutable sequences of Unicode code points", so + builds a new string and leaves the originals as they were.

Conclusion​

first + " " + second gave Bike shop, and "\n" between two strings put them on separate lines. Both sides of + must be text, so wrap numbers in str().

Additional Resources​