repeat_str
Builtin index · Collections & strings
result = repeat_str(s, n)
Input: s, n · Output: result
What it is
s is a Str; n (number of copies). s * n is the shorter spelling for the same thing; the function is not called repeat because that is a loop keyword.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = repeat_str(s, n) | s Strs is a Str.n numbern (number of copies). | result Str | Returns a Str. |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
text = "one\ntwo\nthree"
print(lines(text)) # ("one", "two", "three")
print(chars("abc")) # ("a", "b", "c")
print(repeat_str("ab", 3)) # "ababab"
print(as_text([1, 2, 3]).join(", ")) # "1, 2, 3"
output
("one", "two", "three")
("a", "b", "c")
ababab
1, 2, 3from collections-strings
How it works
repeat_str(s, n) — n copies. "ab" * 3 is the shorter spelling and does the same thing; this is the named form, and it is not called repeat because that is a loop keyword.
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.