In Perl, I can replicate strings with the 'x' operator:
$str = "x" x 5;
Can I do something similar in Python?
>>> "blah" * 5
'blahblahblahblahblah'
Here is a reference to the official Python3 docs:
https://docs.python.org/3/library/stdtypes.html#string-methods
Strings implement all of the common sequence operations...
... which leads us to:
https://docs.python.org/3/library/stdtypes.html#typesseq-common
Operation | Result
s * n or n * s | n shallow copies of s concatenated
Example:
>>> 'a' * 5
'aaaaa'
>>> 5 * 'b'
'bbbbb'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With