Python | Create multiple copies of a string by using multiplication operator

Here, we are going to learn how to create multiple copies of a string by using multiplication operator in Python?
Submitted by IncludeHelp, on September 06, 2018

Given a string and we have to create its multiple copies by using multiplication operator in Python?

If you want to create multiple copies of string, the multiplication operator (*) can be used.

Consider the example – to create N copies 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

Python String Programs »



Related Programs



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.