String Right Justification with Zero Padding

  • Share this:

Code introduction


Right-justifies a string within a given width, padding with zeros if necessary using the built-in str.zfill method.


Technology Stack : str.zfill

Code Type : String processing

Code Difficulty : Intermediate


                
                    
def zfill(string, width=0):
    """
    Right-justify a string in a given width. Pad with zeros if necessary.
    """
    return string.zfill(width)                
              
Tags: