Python Program to Concatenate String

« Previous Program Next Program »

Concatenate String in Python

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.

Python Programming Code to Concatenate String

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':
    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:

concatenate string python

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:

string concatenation program python

Same program on python shell:

python concatenate two strings

Same Program in Other Languages

You may also like to learn or practice the same program in other popular programming languages:

« Previous Program Next Program »


Quick Links
Signup - Login - Give Online Test