To concatenate two string in python, you have to ask from user to enter the first and second string and start concatenating or appending both the string to form a new string say third string. After concatenation of both the string print the value of the third string as output as shown in the program given below.
Following python program ask from user to concatenate two string:
# Python Program - Concatenate String print("Enter 'x' for exit."); string1 = input("Enter first string to concatenate: "); if string1 == 'x': exit(); else: string2 = input("Enter second string to concatenate: "); string3 = string1 + string2; print("\nString after concatenation =",string3); print("String 1 =",string1); print("String 2 =",string2); print("String 3 =",string3);
Here is the sample run of the above Python program to demonstrate how to concatenate two string:
Now supply two string say codes as first string and cracker as second string and then press enter to perform the string concatenation operation using above program and finally print the value of concatenated string automatically as shown here:
Same program on python shell:
You may also like to learn or practice the same program in other popular programming languages: