Q:

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

0

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"

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now