Write a python program to concatenate strings in different ways

In this article, we will write a python program to concatenate strings in different ways.

Write a python program to concatenate strings in different ways

#different ways of concatenation in Python
def concatenation(str1, str2):
    str3 = str1 + ' ' + str2
    print(str3)
    str4 = " ".join([str1, str2])
    print(str4)
    print("% s % s" % (str1, str2))
    print("{} {}".format(str1, str2))


concatenation("source code","examples")
concatenation("Python","source code examples")

Output:

source code examples
source code examples
source code examples
source code examples
Python source code examples
Python source code examples
Python source code examples
Python source code examples

Comments