📜  在 Julia 中获取字符串的重复 – ^运算符

📅  最后修改于: 2022-05-13 01:55:08.439000             🧑  作者: Mango

在 Julia 中获取字符串的重复 – ^运算符

^是 julia 中的运算符,用于将指定的字符串重复指定的次数。

句法:

^(s::Union{AbstractString, AbstractChar}, n::Integer)

参数:

  • s::Union{AbstractString, AbstractChar}:指定字符串或字符
  • n::Integer:指定整数

返回:它返回一个新的重复字符串。示例 1:

Python
# Julia program to illustrate
# the use of operator ^
 
# Get repetition of different strings
println("GFG " ^3)
println("GeekforGeeks " ^2)
println("abc " ^2)
println("a " ^4)


Python
# Julia program to illustrate
# the use of operator ^
 
# Get repetition of different strings
println("1-" ^3)
println("123 " ^2)
println("5& " ^2)
println("0 * 0 " ^4)


输出:

GFG GFG GFG 
GeekforGeeks GeekforGeeks 
abc abc 
a a a a

示例 2:

Python

# Julia program to illustrate
# the use of operator ^
 
# Get repetition of different strings
println("1-" ^3)
println("123 " ^2)
println("5& " ^2)
println("0 * 0 " ^4)

输出:

1-1-1-
123 123 
5& 5& 
0*0 0*0 0*0 0*0