String Padding with Zfill Function

  • Share this:

Code introduction


The function is used to pad a string to a specified width, using a specified character to fill the insufficient part.


Technology Stack : str.zfill(width)

Code Type : String formatting function

Code Difficulty : Beginner


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