×

Python Tutorial

Python Basics

Python I/O

Python Operators

Python Conditions & Controls

Python Functions

Python Strings

Python Modules

Python Lists

Python OOPs

Python Arrays

Python Dictionary

Python Sets

Python Tuples

Python Exception Handling

Python NumPy

Python Pandas

Python File Handling

Python WebSocket

Python GUI Programming

Python Image Processing

Python Miscellaneous

Python Practice

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

Python String Programs »



Related Programs

Advertisement
Advertisement


Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

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