Update appNew update is available. Click here to update.
Last Updated: Sep 13, 2023

Python String Concatenation

Author Tisha
0 upvote


In this article, we will learn how to concatenate strings in Python. We will also see the different methods and their syntax and implementation. We will also look at some examples of Python string Concatenation. 

Python String Concatenation

Python String Concatenation

Concatenating the two strings means merging both strings. Concatenation of "Coding" and "Ninjas" will result in "Coding Ninjas".

Here, we will discuss the different methods with which we can do String Concatenation in Python. Python String Concatenation can be done using the below ways. 

  • Using + operator. 
  • Using join() method. 
  • Using % operator. 
  • Using format() function. 
  • Using ',' comma.
  • Using f-string (Literal String Interpolation).

Method 1: Python String Concatenation using + Operator

The simplest Method is to use the + Operator for the Python string Concatenation. This Operator is used to add multiple strings together. Here, the arguments should be a string. The + Operator joins the string stored in v1 and v2 and stores it in another variable, v3.

# Defining the strings
v1 = "Coding "
v2 = "Ninjas"
# The + Operator used to combine the strings
v3 = v1 + v2


Coding Ninjas

Method 2: Python String Concatenation using join() Method

The join() method returns a string with a str separator joining the sequence elements. This Method will combine the strings stored in the v1 and v2 variables. This Method only accepts the list as the argument; the list size can be anything. 

v1 = "Coding"
v2 = "Ninjas"
# join() method used to combine strings
print("".join([v1, v2]))
# join() method is used to combine
# string with the separator Space(" ")
v3 = " ".join([v1, v2])


Coding Ninjas

Method 3: Python String Concatenation using % Operator

The % operator is used for string formatting. It can be used for string concatenation also. This Operator is useful when we need to concatenate the strings and perform simple formatting. The % denotes string data type. The values in both the variables will be passed to the string %s and become "Coding Ninjas".

v1 = "Coding"
v2 = "Ninjas"
# % Operator used to combine string
print("% s % s" % (v1, v2))


Coding Ninjas

Method 4: Python String Concatenation using format() function 

This Method allows value formatting and multiple substitutions in Python. This Method is used in Python for string formatting as string.format(). This Method concatenates the elements within a string through positional formatting. In this Method, curly braces {} will be used to set the position of the strings. The first curly brace stores the first variable, and the second curly brace stores the second variable. Finally, it will print  "Coding Ninjas".

v1 = "Coding"
v2 = "Ninjas"
print("{} {}".format(v1,v2))
# store the output in another variable
v3 = "{} {}".format(v1, v2)


Coding Ninjas
Coding Ninjas

Method 5: Python String Concatenation using (, comma)

When you need to include only one whitespace, one of the best alternatives to string concatenation using the “+” operator is “,”

v1 = "Coding"
v2 = "Ninjas"
# combine data types with the single whitespace.
print(v1, v2)


Coding Ninjas

Method 6: Python String Concatenation using f-string

If you use Python 3.6+, you can easily use the f-string function for string concatenation. This new method to format the strings was introduced in PEP 498 - Literal String Interpolation.

v1 = 'Coding'
v2 = 'Ninjas'
v3 = f'{v1} {v2}'
print('String Concatenation =', v3)


String Concatenation = Coding Ninjas

You can practice by yourself with the help of online python compiler for better understanding.

Frequently Asked Questions

What is the most efficient way to concatenate strings in Python?

Use the join() method in Python for efficient string concatenation; it creates one string object. In contrast, the + operator generates a new object each time it's used.

How to concatenate two strings?

Using the + operator or the str.join() method, you can concatenate two strings in Python.

What are the different types of concatenation?

There are two types of concatenation: Partitioned concatenation and Sequential concatenation.

How does Python handle string concatenation?

Using the '+' Operator, 'join()' method, '%' operator, 'f-string' and using the 'format()' function. 'f-strings' was introduced in Python 3.6 only. It provides a concise way to embed expressions inside string literals.

How many strings can you concatenate in Python?

Concatenate strings in Python by using the + operator for different strings and the * operator for repeating the same string.

What symbol is used for concatenation in Python?

The + operator is used to concatenate strings in Python. To combine two or more strings into one new string that comprises the contents of the concatenated strings, you can just use the + operator. For instance, the phrase "Hello, world!" would be produced by adding "Hello, " and "world!".

Why avoid string concatenation?

String concatenation is generally avoided in Python for quite a few reasons. In Python, string concatenation can be inefficient, particularly while concatenating many strings. Excessive string concatenation can make code harder to read and understand, especially when long concatenation chains are involved. 


In this article, we have learned how to concatenate strings in Python. We have also seen the different functions and methods with which we can do Python string Concatenation. We have also seen the programming and some examples of it. 

You can also refer to the below articles:

You can learn the basics of Java and data structures and algorithms in Java on Coding Ninjas. Refer to our guided path on code studio to learn Competitive Programming, Javascript System Design, etc. Enroll in our courses and refer to the mock test and problems available. Also, look at the interview experiences for placement preparations.

Happy Learning, Ninjas.

Previous article
Python String replace() Method
Next article
Capitalize() in Python