---
title: "Concatenate Two Strings in Python : A Complete Tutorial Guide"
description: "Learn how to concatenate two strings in Python using just about every method you can think of in this handy tutorial."
canonical: "https://adamtheautomator.com/concatenate-two-strings-python/"
---

# Concatenate Two Strings in Python : A Complete Tutorial Guide

> Learn how to concatenate two strings in Python using just about every method you can think of in this handy tutorial.

Source: https://adamtheautomator.com/concatenate-two-strings-python/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![Concatenate Two Strings in Python : A Complete Tutorial Guide](https://adamtheautomator.com/wp-content/uploads/2021/06/How-String-Concatenation-Works-in-Python.jpg)

# Concatenate Two Strings in Python : A Complete Tutorial Guide

[![](https://secure.gravatar.com/avatar/6b2192cfd275e1506ff2901563cba75d8c88d5223c34e30d404b54de80b2fa5c?s=192&d=mm&r=g)Shahzaib Kamal](https://adamtheautomator.com/author/shahzaib-kamal/)4 June 20214 min. read

Categories: [IT Ops](/category/it-ops/)

Tags:[Python](/tag/python/)

Table of Contents

*   [Prerequisites before you Concatenate Two Strings in Python](#h-prerequisites)
*   [The + Operator](#h-the-operator)
*   [The Join() Method](#h-the-join-method)
*   [The String Formatting % Operator](#h-the-string-formatting-operator)
*   [The Format() Method](#h-the-format-method)
*   [The f-string Construct](#h-the-f-string-construct)
*   [Python Gotcha: String Type Conversions](#h-python-gotcha-string-type-conversions)
*   [Conclusion](#h-conclusion)

String concatenation is a common practice in Python. Like with many other programming languages though, are you sure you’re using the right method? If you’re wondering how to concatenate two strings in Python and more, stay tuned.

In this tutorial, you are going to learn how to perform string concatenation in many unique and possible ways to help you pick the best method for your unique situation.

Read on!

## Prerequisites before you Concatenate Two Strings in Python

This tutorial is hands-on and will include many different demos. If you intend to follow along, be sure you have the following:

*   [Python v3+](https://www.python.org/downloads/) on any operating system. This tutorial will use Python v3.8.4.

Related:[How Do You Install Python 3.6?](https://adamtheautomator.com/install-python-36/)

*   A code editor like [Visual Studio (VS) Code](https://code.visualstudio.com/download) that can [interpret and execute Python code](https://code.visualstudio.com/docs/languages/python).
*   A Python script you can reuse to walk through each demo

## The `+` Operator

One of the most popular methods to concatenate two strings in Python (or more) is using the `+` operator. The `+` operator, when used with two strings, concatenates the strings together to form one.

In a Python script, copy, paste and execute the code below. This simple script creates two string variables `a` and `b`. It then uses the `+` operator to merge or concatenate them together to form a single string.

```python
a = "You are "
b = "learning Python"

a + b
```

The `+` operator doesn’t just concatenate two strings in Python. You can add as many as you’d like. The below example creates another string variable and adds it to the end of the string.

```python
a = "You are "
b = "learning "
c = "python"

a + b + c
```

You will see you get the same output for both examples.

## The `Join()` Method

The `join()` method is another good way to concatenate two strings in Python. Similar to the `+` operator, the `join()` method requires at least two strings to join together. The `join()` method isn’t necessarily meant to concatenate strings, but to join list elements together.

To use the `join()` method, first create a list of strings. The example below is creating a string to join all list elements with (a space). The `join()` method is on all string objects in Python so it’s calling the method passing in three string variables defined in a [list](https://www.w3schools.com/python/python_lists.asp) `[a,b,c]`.

```python
a = "You are"
b = "learning python"
c = "using join method"

" ".join([a, b, c])
```

![Python join method](https://adamtheautomator.com/wp-content/uploads/2021/06/join-method.png)

Python join method

Instead of a space (`" "`) to join the list elements by, you can use any character(s) you’d like, as shown below.

```python
a = "You are"
b = "learning python"
c = "using join method"

"*".join([a, b, c])
```

You can see below that the spaces have been replaced by asterisks.

![Python join method with asterisks](https://adamtheautomator.com/wp-content/uploads/2021/06/join-method-with-asterisks.png)

Python join method with asterisks

## The String Formatting `%` Operator

Python has a concept called [string formatting](https://realpython.com/python-string-formatting/). String formatting is a feature of Python that allows you to dynamically insert strings within strings with placeholders. Typically, most don’t consider using string formatting to concatenate strings but it’s possible.

Let’s say you need to concatenate the three strings you’ve been working with previously. To be more specific, you’d like to concatenate two strings in Python together separated by a space.

To concatenate multiple strings together with the string formatting construct `%`, first create a string with two placeholders or _Python format specifiers_ representing where each string will be placed (`"%s %s"`). Each placeholder is represented by `%s`.

Once you have the intended string, then use the `%` construct to pass a list of strings into that “placeholder string”, as shown below.

```python
a = "You are"
b = "learning"

"%s %s" % (a, b)
```

Even if `a` and `b` were integers (more later), you would still get the expected string because Python would cast each integer to a string.

```python
a = 1
b = 2

"%s %s" % (a, b)
```

## The `Format()` Method

You can also use another Python formatting technique with the `format()` method. Like the `%` string formatting construct, the `format()` method allows you to define placeholders in a string and pass one or more strings inside.

Instead of using `%s` placeholders, you will use curly braces (`{}`) to represent the location where you’d like to place the strings.

Related:[Getting Started: Python Functions for Newbies](https://adamtheautomator.com/python-function-return/)

Using the built-in string method `format()`, the example below creates a string with placeholders (`{}`) you’d like to insert strings `a`, `b` and `c` into. It then passes the values of each string variable with as arguments to the `format()` method.

```python
a = "You are"
b = "learning python"
c = "using format method"

"{} {} {}".format(a, b, c)
```

Once executed, you can see that [Python](https://adamtheautomator.com/python-function-return/) replaces each `{}` with the value of `a`, `b` and `c` from left to right.

![Python format method](https://adamtheautomator.com/wp-content/uploads/2021/06/format-method.png)

Python format method

The “placeholder” string, like using the `%` construct can be anything as long as you specify the same number of “placeholders” as values you’re passing into it.

```powershell
a = "You are"
b = "learning python"
c = "using format method"

print("{}*{}*{}".format(a, b, c))
```

![Python format method with asterisks](https://adamtheautomator.com/wp-content/uploads/2021/06/format-method-2.png)

Python format method with asterisks

## The `f-string` Construct

For the final way to concatenate two strings in Python, check out the `f-string` construct. Another string formatting technique, `f-string` allows you to define “placeholders” and then pass in string values to those placeholders.

You can see below the concept is the same as the other string formatting techniques. Only this time, you start the “placeholder string” with an `f` and enclose the string variables inside of the curly braces within.

```python
a = "You are"
b = "learning python"
c = "using f-string method"

f"{a} {b} {c}"
```

![concatenate two strings in Python via Python f-string method](https://adamtheautomator.com/wp-content/uploads/2021/06/f-string-method.png)

concatenate two strings in Python via Python f-string method

## Python Gotcha: String Type Conversions

When concatenating strings together in Python, pay attention to [types](https://www.w3schools.com/python/python_datatypes.asp). You will come across unexpected behavior if, for example, you intend to concatenate two strings in Python together but use a non-string type instead.

For example, using the `+` operator, take a look at the following code and the output. Notice that Python returns an error. It returns an error because `3` is an integer and not a string.

```python
a = "You are "
b = "learning "
c = "python "
d = 3
a + b + c + d
```

![Python error when using different data types](https://adamtheautomator.com/wp-content/uploads/2021/06/error-when-try-with-number.png)

Python error when using different data types

If you need to concatenate a different type like an integer, always remember to enclose it with single or double quotes, like below.

```powershell
a = "You are "
b = "learning "
c = "python "
d = "3"
a + b + c + d
```

## Conclusion

You should now have the proper understanding of how to concatenate two or more strings in Python using many unique methods. Whether it’s intended concatenation methods like the `+` operator or via string formatting, you should now know how to work with both.

Which method you prefer for your real life Python project?

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Fconcatenate-two-strings-python%2F&text=Concatenate%20Two%20Strings%20in%20Python%20%3A%20A%20Complete%20Tutorial%20Guide)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Fconcatenate-two-strings-python%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Fconcatenate-two-strings-python%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2026/02/featured_image-3.webp)

### [How to Ace the Modern Coding Interview as a SysAdmin](/ace-modern-coding-interview-sysadmin/)

Master coding interviews for sysadmin and DevOps roles with practical preparation strategies. Learn Python, Bash, and platform-specific techniques that translate your operational experience into interview success.

![](https://adamtheautomator.com/wp-content/uploads/2023/11/pytorch.jpg)

### [How to Install PyTorch on Window](/pytorch/)

Embark on this journey and unleash PyTorch’s potential — your gateway to machine learning and AI exploration, through this ATA Learning tutorial!

![](https://adamtheautomator.com/wp-content/uploads/2023/08/install-python-macos.jpg)

### [Get Started with Programming and Install Python on macOS](/install-python-on-macos/)

Learn how to get started with programming and automation and install Python on macOS in this ATA Learning tutorial!

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
