String Right Alignment with Filling Character

  • Share this:

Code introduction


Right-aligns the string within a field of a specified width, filling with the specified character, defaulting to spaces. If the specified width is negative, the string is left-aligned.


Technology Stack : String manipulation

Code Type : String operation

Code Difficulty : Intermediate


                
                    
def zfill(string, width=0, fillchar=' '):
    """
    Right-aligns the string in a field of a specified width, filling with zeros.
    """
    return string.zfill(width)