String Length Extension with Padding

  • Share this:

Code introduction


Extend the length of the first string arg1 to be the same as the second string arg2, padding with spaces if necessary.


Technology Stack : Built-in library

Code Type : String formatting

Code Difficulty : Intermediate


                
                    
def azip(arg1, arg2):
    if isinstance(arg1, str) and isinstance(arg2, str):
        return arg1.zfill(len(arg2))
    else:
        raise ValueError("Both arguments must be strings")