Member-only story

How to Concatenate Strings in Python| Python Tutorial

5 Different Ways to Concatenate Strings, Including Examples

Sanjay Priyadarshi
5 min readNov 27, 2022
Photo by Lauren Mancke on Unsplash

Strings are immutable objects.

It means you can’t modify the existing string. The only thing you can do with strings is to add another string to an existing one.

Adding a new string to an already existing string can be done in several ways.

In this article, we will discuss how to add one string to existing strings in python.

Let’s look at different methods through which you can do this.

1. Use the += operator to concatenate strings

With the help of the += operator, you can concatenate any number of strings.

Using a += operator is simple.

Let’s see how to concatenate two strings using the += operator.

Example

old_string = "Hello"

add_string = "Hey"


print("This is the existing string: ", str(old_string))

print("The string to be added: ", str(add_string))


old_string += add_string


print("The concatenated string is: ", str(old_string))


#Result:
This is the existing string: Hello
The string to be added: Hey
The concatenated string is: HelloHey

--

--

Sanjay Priyadarshi
Sanjay Priyadarshi

Written by Sanjay Priyadarshi

Join a Community of People Who Love Javascript, Programming and Technology — codertoentrepreneurs.substack.com

No responses yet