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

PythonServer Side ProgrammingProgramming

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:


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:


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

Updated on 12-Jun-2020 13:12:15