String Left Padding Function

  • Share this:

Code introduction


This function takes a string and a width as arguments. It pads the string on the left with spaces until the string reaches the specified width.


Technology Stack : str.zfill(width)

Code Type : String fill function

Code Difficulty :


                
                    
def zfill_string(s, width=0):
    """
    Right-justify a string in a filled field of a given width. Padding is done on the left.
    """
    return s.zfill(width)