;

Python Program to Copy a String to Another String


Tutorialsrack 27/04/2020 Python

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.

Program 1: Copy a String to another String

Python 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)
Output

Enter The String: Tutorials Rack

The Final String : Str2  =  Tutorials Rack

The Final String : Str3  =  Tutorials Rack

Program 2: Copy a String To Another String using For Loop

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)
Syntax - SELECT Statement

Enter The String: Tutorials Rack is an Online Learning Website

The Final String : Str2  =  Tutorials Rack is an Online Learning Website

Program 3: Using the For Loop with Range to Copy a string

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 range(len(str1)):
    str2 = str2 + str1[i]
    
print("The Final String : Str2  = ", str2)
Output

Enter The String: Tutorials Rack is an Online Learning Website

The Final String : Str2  =  Tutorials Rack is an Online Learning Website


Related Posts



Comments

Recent Posts
Tags