Skip to content

How do I append one string to another in Python?

You can use the "+" operator to concatenate two strings in Python. Here's an example:

Summation of strings in Python

python
string1 = "Hello"
string2 = "world"
result = string1 + " " + string2
print(result)  # Output: "Hello world"

<div class="alert alert-info flex not-prose"> Watch a course Python - The Practical Guide</div>

You can also use the += operator to append one string to another:

Summation of strings in Python using += operator

python
string1 = "Hello"
string2 = "world"
string1 += " " + string2
print(string1)  # Output: "Hello world"

or the join() method of the first string, passing the second string as an argument:

Join multiple strings in Python

python
string1 = "Hello"
string2 = "world"
result = " ".join([string1, string2])
print(result)  # Output: "Hello world"

Note that join() method expects a list of strings, so you have to pass a list containing the two strings you want to join.

Do you find this helpful?

Dual-run preview — compare with live Symfony routes.