Python program to concatenate two string

In this tutorial, we are going to learn writing a python program to concatenate two strings.

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 ‘pythonprogram’.

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

                    then the output should be ‘learnpython’.

Our logic to concatenate two string

  • Firstly, take two strings as inputs from the user.
  • Then, use string concatenation methods to join the strings together
  • And finally, return the concatenated string as an output of our program.

Algorithm to concatenate two string

Step1:  Start

Step2:   Take two strings as input from the user.

Step3: print string1 + string2

Step4: Stop

Python code to concatenate two string

#taking input from the user
str1 = input('Enter first string: ')
str2 = input('Enter second string: ')
#using string concatenation method ‘+’
str3 = str1 + str2
print("String after concatenation :",str3)

Output 1:

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

Explanation:

The user is given the input ‘quescol’ and ‘website’, now to join them together our program used the ‘+’ operator which joins two strings together and the final string generated is ‘quescolwebsite’.

Output 2:

Enter first string: quescol is
Enter second string: website
String after concatenation : quescol iswebsite

Explanation:

The user is given the input ‘quescol’ and ‘website’, now to join them together our program used the ‘+’ operator which joins two strings together and the final string generated is ‘quescol iswebsite’.