Computer >> Computer tutorials >  >> Programming >> Python

How to join two strings to convert to a single string in Python?


To join 2 strings in Python, we can use the concatenation operator, '+'. For example:

str1 = "Hello"
str2 = "World"
str3 = str1 + str2
print str3

This will give us the output:

HelloWorld

We can also use str.join(seq) to join multiple strings together. For example:

s = "-";
seq = ("a", "b", "c"); # This is sequence of strings.
print s.join( seq )

This will give us the output:

a-b-c

Note that the str we give is used as the seperator when joining the strings together.