How to Concatenate Strings in Python - Plus and Join

Concatenation of strings in Python is possible by using plus and join method. You can also do it in other ways. But in my point of view, these two are the best methods.

Python string concatenation


What are Strings?

In data science, you will have to concatenate strings on many occasions. You can find this concept helpful in your project as well.

For example:


Stringa='Uncle'

Stringb='is'

Stringc='Married'


I have got data in three strings. Here my interest is I need to read these in a single line. So in this type of scenario, the concept of concatenation is helpful.


Best methods to concatenate strings

Here are the two best methods. One is you can use plus operator. The other one you can use join method.


#1: Using plus operator


Stringa='Uncle'

Stringb='is'

Stringc='Married'

print(Stringa + ' ' + Stringb + ' ' + Stringc)


Result:

Uncle is Married


#2: Using the join method with separator.


Stringa='Uncle'

Stringb='is'

Stringc='Married'

a=' '.join([Stringa, Stringb, Stringc])

print(a)


Result:

Uncle is Married


Reference books


Reference links

Comments

Most Popular

7 AWS Interview Questions asked in Infosys, TCS

How to Decode TLV Quickly

Hyperledger Fabric: 20 Real Interview Questions