Skip to content

Move pad_number() to strtools #58

@ehrenfeu

Description

@ehrenfeu

Then implement the Examples as unit tests.

Originally posted by @lguerard in #49 (comment)

def pad_number(index, pad_length=2):
"""Pad a number with leading zeros to a specified length.
Parameters
----------
index : int or str
The number to be padded
pad_length : int, optional
The total length of the resulting string after padding, by default 2
Returns
-------
str
The padded number as a string
Examples
--------
>>> pad_number(7)
'07'
>>> pad_number(42, 4)
'0042'
"""
return str(index).zfill(pad_length)

Metadata

Metadata

Assignees

Labels

refactoringRewrite / rename / move code etc.

Type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions