String Zero Padding with zfill()

  • Share this:

Code introduction


The zfill() function is used to pad a string with zeros on the left until it reaches a specified length. If arg1 is a negative number, a ValueError will be raised.


Technology Stack : Built-in function

Code Type : String formatting function

Code Difficulty :


                
                    
def zfill(arg1, arg2=0):
    return str(arg1).zfill(arg2)