Home » Python programs

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




Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.