concat the string in python by R4R Team

- concat() is a python function predefined in 'operator' module that are able to concat the two string.

Syntax-

operator.concat(string,string)

Example-

string1 is "math"
string2 is "book"
concat(string1,string2) will return 'mathbook'


program-

import operator
print("Enter first string")
s1=input()
print("Enter second string")
s2=input()

#first way of concatination
s=operator.concat(s1,s2)
print("After concatination of both string -",s)

#second way of concatination
s=s1+s2
print("After concatination of both string -",s)


output-

Enter first string
Hello
Enter second string
world
After concatination of both string - Helloworld
After concatination of both string - Helloworld

Enter first string
Tea
Enter second string
water
After concatination of both string - Teawater
After concatination of both string - Teawater


-In this program, we take two string as a input then concat both string with the help of the concat() function defined in operator module
-that's by we import operator module.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!