Table of Contents

Python Code to Read two Strings & Concatenate the Strings.

 

Python code implementation without user-defined functions & classes

Code: 
# Python code to Read two Strings & Concatenate the Strings

a = input("Enter First String: ")
b = input("Enter Second String: ")
c = a+b
print("Concatenated String is: ",c)
Executing Python Script: 
python program.py
Enter First String: I love
Enter Second String: Python Programming

 

Output: 
Concatenated String is:  I lovePython Programming

 

 

Python code implementation using function

Code: 
# Python code to Read two Strings & Concatenate the Strings using Function

def concatenate_string_function(a_string, b_string):
    return a_string + b_string

a = input("Enter First String: ")
b = input("Enter Second String: ")
c = concatenate_string_function(a, b)
print("Concatenated String is: ",c)

 

Executing Python Script: 
python program.py
Enter First String: I love
Enter Second String: Python Programming

 

Output: 
Concatenated String is:  I lovePython Programming

 

 

 

Python code implementation using Classes

Code: 
# Python code to Read two Strings & Concatenate the Strings using Class

class Concatenate_string_class(object):
    def concatenate_string_function(self, a_string, b_string):
        self.a_string = a_string
        self.b_string = b_string
        return self.a_string + self.b_string

a = input("Enter First String: ")
b = input("Enter Second String: ")

#Create the Object
Object_1 = Concatenate_string_class()

#Call the function using created Object
c = Object_1.concatenate_string_function(a, b)
print("Concatenated String is: ",c)
Executing Python Script: 
python program.py
Enter First String: I love
Enter Second String: Python Programming

 

Output: 
Concatenated String is:  I lovePython Programming

 

 

 

 

 

Enjoy Python Code By Pythonbaba 🙂