Python program to concatenate String using join() method

In this tutorial, we are going to learn writing a python program to concatenate two strings using python inbuilt join() method.

Problem Statement

For two input strings that are given by the user, we need to join them together and return the final string as an output.

For example:

Case1: If the user gives the strings ‘python’ and ‘program’

                    then the output should be ‘pythonfun’.

Case2: If the user gives the inputs as ‘learn’ and ‘python’,

                    then the output should be ‘learnpython’.

Our logic to concatenate two string using join() function

  • Firstly, take two strings as inputs from the user.
  • then, use string concatenation methods to join the strings together. Here we are using join() method.
  • And finally, return the concatenated string as an output of our program.

Algorithm to concatenate two string using join() function

Step1:  Start

Step2:   Take two strings as input from the user.

Step3: print “ ”.join( [string1, string2] )

Step4: Stop

Python code to concatenate two string using join() function

#taking inputs from the user
str1 = input('Enter first string: ')
str2 = input('Enter second string: ')
#printing the output after using join() method
print("String after concatenation :","".join([str1, str2]))

Output:

Enter first string: quescol
Enter second string: website
String after concatenation : quescolwebsite

Explanation:

In this example, the two strings entered by the user are ‘quescol’ and ‘website’ after using the join() method which took two strings as iterable and returns the output as ‘quescolwebsite’.