Python Program to Copy String

« Previous Program Next Program »

Copy String in Python

To copy string in python, you have to ask from user to enter a string and then copy that string into another string variable and finally print the value of that string variable as shown in the program given here.

Python Programming Code to Copy String

Following python program ask from user to enter a string to copy that string:

# Python Program - Copy String

print("Enter 'x' for exit.");
string = input("Enter any string to copy: ");
if string == 'x':
    print("Copying string 1 (string) into string 2 (cstring)...");
    cstring = string;
    print("\nString 2 after successfully copied =",cstring);
    print("\nString 1 =",string,"\nString 2 =",cstring);

Here is the sample run of the above Python program illustrating how to copy string:

copy string python

Now enter any string say codescracker and then press enter key to copy the given string into another string variable and then print it out the value of that variable where the given string is copied as shown below:

copy string program python

Same program on python shell:

python copy string

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