In this tutorial, we are going to learn writing a python program to concatenate two strings using python inbuilt join() method.
For two input strings that are given by the user, we need to join them together and return the final string as an output.
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
Step2: Take two strings as input from the user.
Step3: print “ ”.join( [string1, string2] )
Python code to concatenate two string using join() function
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’.