- Python Code to Read two Strings & Concatenate the Strings.
- Python code implementation without user-defined functions & classes
- Python code implementation using function
- Python code implementation using Classes
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
if[typeof ez_ad_units != 'undefined']{ez_ad_units.push[[[250,250],'pythonbaba_com-large-leaderboard-2','ezslot_5',127,'0','0']]};__ez_fad_position['div-gpt-ad-pythonbaba_com-large-leaderboard-2-0'];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 🙂
PythonBaba
Our team loves to write in Python, Linux, Bash, HTML, CSS Grid, CSS Flex, and Javascript. We love to write technical articles. Currently exploring Data Science, Machine learning and Artificial intelligence.