String Padding with Zeros

  • Share this:

Code introduction


The zfill function is used to pad a string with zeros on the left until it reaches the specified length.


Technology Stack : String, built-in function

Code Type : String manipulation function

Code Difficulty : Intermediate


                
                    
def zfill(arg1, arg2):
    if not isinstance(arg1, str):
        raise ValueError("arg1 must be a string")
    return arg1.zfill(arg2)