pad_string function

Pad String with Spaces

Pad String with Spaces

Adds spaces to the beginning or end of strings until it reaches the maxlength. Used for aligning text.

pad_string(str, maxlength = 1, location = "beginning")

Arguments

  • str: string
  • maxlength: length to pad to
  • location: either "beginning" to pad the left or "end" to pad the right

Returns

Padded string

Examples

pad_string("bob", maxlength=10) pad_string("bob", maxlength=10, location="end")
  • Maintainer: John Harrold
  • License: BSD_2_clause + file LICENSE
  • Last published: 2025-01-07