Write a Python Program to Concatenate/Join Two Strings Using Operator (User Input)
Introduction
String concatenation means joining two or more strings together. In Python, we use the + operator to join strings.
Logic to Write the Code
- Start the program.
- Take first string input from the user.
- Take second string input from the user.
- Use
+operator to join both strings. - Print the result.
- End the program.
Source Code (Beginner Friendly)
# Python program to concatenate two strings using + operator
# Taking input from user
str1 = input("Enter first string: ")
str2 = input("Enter second string: ")
# Concatenating strings
result = str1 + str2
# Displaying result
print("Concatenated String:", result)
Sample Output
Enter first string: Hello
Enter second string: World
Concatenated String: HelloWorld
Viva Questions with Answers
1. What is string concatenation?
String concatenation means joining two or more strings.
2. Which operator is used to join strings in Python?
The + operator is used to join strings.
3. What does the input() function do?
It takes input from the user.
4. Can we join a string and a number directly using +?
No, it will give a TypeError unless the number is converted to string.
5. How can we add space between two strings while joining?
By adding a space inside quotes:result = str1 + " " + str2
