pad_left
Builtin index · Collections & strings
result = pad_left(s, width, [fill=" "])
Input: s, width, fill · Output: result
What it is
s is a Str; width (number, target character count); optional fill (single-character Str, default " "). Pads on the left to width characters; a string already that wide is returned unchanged, never truncated.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = pad_left(s, width, [fill=" "]) | s Strs is a Str.width numberwidth (number, target character count).fill Str, optional (default " ")optional fill (single-character Str, default " "). | 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.
print("-" * 40) # "----------------------------------------"
print("hello".substr(0, 2).replace("e", "i")) # "hi"
print(pad_left(str(7), 3, "0")) # "007"
print(proper("ada lovelace")) # "Ada Lovelace"
print(count("banana", "a")) # 3
---------------------------------------- hi 007 Ada Lovelace 3
from collections-strings
How it works
pad_left(s, width, [fill]) / pad_right(...) — pad to a width in CHARACTERS. A string already at or past the width is returned unchanged rather than truncated: padding is for lining columns up, and silently losing text to make a column fit is never what was meant.
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.