How to concatenate two strings in python?

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.
e.g.,
a="Hello" b=" World" print(a+b)
e.g.,

- 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.
e.g.,
a="5" print(a*3)

- Using join() function- join() is used to concatenate two strings.
e.g.,
a="Hello" b="World" print(" ".join([a, b]))

This is all about concatenate two strings in python.
Subscribe
Login
Please login to comment
0 Discussion