perl 可以像 python 一样乘以字符串吗? [英] Can perl do multiplying a string like python?
本文介绍了perl 可以像 python 一样乘以字符串吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能的重复:
如何在 Perl 中重复字符串?
在蟒蛇中
"a" * 4
结果为aaaa"
Perl 也可以这样做吗?
Can Perl do this too?
推荐答案
这是重复 (x
) 运算符.
It's the repetition (x
) operator.
'a' x 4 # 'aaaa'
x
运算符还可以创建重复元素的列表.
The x
operator can also create lists of repeated elements.
('a','b') x 4 # 'a','b','a','b','a','b','a','b'
如果要创建列表,必须使用括号(或 qw()
).
Using parens (or qw()
) is mandatory if you want to create a list.
运算符记录在 perlop 中.
这篇关于perl 可以像 python 一样乘以字符串吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文