String Right-Justification with Filling

  • Share this:

Code introduction


This function returns a right-justified version of the string, filled with the specified fill character on the left if necessary.


Technology Stack : string.zfill(width)

Code Type : String processing

Code Difficulty : Beginner


                
                    
def zfill(string, width=0, fillchar=' '):
    """
    This function returns a right-justified version of the string, filled with the specified
    fill character on the left if necessary.
    """
    return string.zfill(width)