In this Python Program, we will learn how to copy a string to another string. There are various ways to copy a string to another string in python.
Here is the source code of the program to copy a string to another string.
# Python Program to Copy a String to Another String
# Take the Input From the User
str1 = input("Enter The String: ")
str2 = str1
str3 = str1[:]
print("The Final String : Str2 = ", str2)
print("The Final String : Str3 = ", str3)
Enter The String: Tutorials Rack
The Final String : Str2 = Tutorials Rack
The Final String : Str3 = Tutorials Rack
Python Program to Copy a String to Another String using For Loop
# Python Program to Copy a String to Another String using For Loop
# Take the Input From the User
str1 = input("Enter The String: ")
str2 = ''
for i in str1:
str2 = str2 + i
print("The Final String : Str2 = ", str2)
Enter The String: Tutorials Rack is an Online Learning Website
The Final String : Str2 = Tutorials Rack is an Online Learning Website
# Python Program to Copy a String to Another String using For Loop
# Take the Input From the User
str1 = input("Enter The String: ")
str2 = ''
for i in range(len(str1)):
str2 = str2 + str1[i]
print("The Final String : Str2 = ", str2)
Enter The String: Tutorials Rack is an Online Learning Website
The Final String : Str2 = Tutorials Rack is an Online Learning Website
Comments