String Padding with zfill

  • Share this:

Code introduction


This function is used to pad a string to a specified width. If the length of the string is less than the specified width, it will be padded with the specified character on the left.


Technology Stack : str.zfill(width)

Code Type : String operation

Code Difficulty : Intermediate


                
                    
def zfill(string, width, fillchar=' '):
    return str(string).zfill(width)