Python String Concatenation

There are multiple ways to concatenate string in Python. You can use the traditional + operator, or String Join or just separate the strings using comma. In this article, we will show you, how to do string concatenation in Python Programming language with examples.

Python string concatenation Example

This is the basic example of Python string concatenation. Here, we are using + operator to concatenate a and b.

str1 = 'a' + 'b'
print(str1)

OUTPUT

If you use the * operator along with a numeric value then that string will be repeated by given number.

Python String and int Concatenation

Unlike most of the programming languages, Python doesn’t implicitly convert an integer to string to perform concat. As you can see, it was throwing an error TypeError: can only concatenate str (not “int”) to str

text = 'Tutorial Gateway'
year = 2018
print(text + year)

OUTPUT

To resolve this, you have to use str function to convert that int value year to string.

text = 'Tutorial Gateway '
year = 2018
print(text + str(year))

OUTPUT

Python String Concatenation example 4

Let me use all the available options to concatenate strings in one example.