python重载运算符乘法_Python | 使用乘法运算符创建一个字符串的多个副本

python重载运算符乘法

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

给定一个字符串,我们必须通过在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

考虑示例– 创建字符串的N个副本

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


翻译自: https://www.includehelp.com/python/create-multiple-copies-of-a-string-by-using-multiplication-operator.aspx

python重载运算符乘法

你可能感兴趣的:(python重载运算符乘法_Python | 使用乘法运算符创建一个字符串的多个副本)