Python Practical Assignment 9.1

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

  1. Start the program.
  2. Take first string input from the user.
  3. Take second string input from the user.
  4. Use + operator to join both strings.
  5. Print the result.
  6. 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


Spread the love

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top