A collection of one or more characters put in single, double or triple quotes is known as string. e.g.,- ‘Hello’, “Python”, “””Pythonpoint”””, etc.
Before we proceed, recall that strings are immutable. Thus, every time you perform something on string that changes it, python will internally create a new string rather than modifying the old string.
Here we’ll see how to concatenate two strings in python. There are different methods to do this.
- Using ‘+’ sign – We have used this operator as arithmetic operators before for addition. But when used with strings, + operator performs concatenation rather than addition.
a="Hello" b=" World" print(a+b)
- Using ‘*’ sign – We have used this operator as arithmetic operator before for multiplication. But when used with strings, * operator perform concatenation for the same string also known as replication.
- Using join() function- join() is used to concatenate two strings.
a="Hello" b="World" print(" ".join([a, b]))
This is all about concatenate two strings in python.