Python Create multiple copies of a string by using multiplication operator

Here, we will figure out how to make numerous duplicates of a string by utilizing increase administrator in Python?

Given a string and we need to make its numerous duplicates by utilizing increase administrator in Python?

In the event that you need to make different duplicates of string, the augmentation administrator (*) can be utilized.

Think about the example – to make N duplicates of a string

Example:

Input:
str1 = "Hello"
n = 3 

logic:
str2 =str1*3

Output:
str2= "HelloHelloHello"

Program:

# Python program to create N copies 
# of a given string 

# define inputs: string and N 
str1 = "Hello"
n = 3

# create copies 
str2 = str1 * 3 

# print
print "str1: ", str1 
print "str2: ", str2

Output:

str1:  Hello
str2:  HelloHelloHello

Leave a Comment

error: Alert: Content is protected!!