String class zfill method¶
This page explains the String
class zfill
method.
What method is this?¶
The zfill
method returns a zero-filled string with the specified widgth (number of total characters).
Basic usage¶
The zfill
method required the width
argument (int
or ap.Int
type).
It determines the number of total characters.
A return value becomes copied ap.String
value.
import apysc as ap
ap.Stage(
stage_width=0,
stage_height=0,
background_color=ap.Color("#333"),
stage_elem_id="stage",
)
string: ap.String = ap.String(value="1")
string = string.zfill(width=1)
ap.assert_equal(string, "1")
string = string.zfill(width=3)
ap.assert_equal(string, "001")
string = string.zfill(width=5)
ap.assert_equal(string, "00001")
ap.save_overall_html(dest_dir_path="string_zfill_basic_usage/")
zfill method API¶
Note: the document build script generates and updates this API document section automatically. Maybe this section is duplicated compared with previous sections.
[Interface signature] zfill(self, *, width: Union[int, ForwardRef('Int')]) -> 'String'
[Interface summary]
Return a copy of the string left filled with 0.
[Parameters]
width
: Union[int, “Int”]A width (length) of the string.
[Returns]
result
: StringA result string.
[Examples]
>>> import apysc as ap
>>> _: ap.Stage = ap.Stage()
>>> string: ap.String = ap.String("1")
>>> string = string.zfill(width=1)
>>> string
String("1")
>>> string = string.zfill(width=3)
>>> string
String("001")
>>> string = string.zfill(width=5)
>>> string
String("00001")