String Right Alignment with zfill Method

  • Share this:

Code introduction


Right-aligns a string within a given width by padding it with spaces on the left using the zfill method of string.


Technology Stack : String

Code Type : String processing

Code Difficulty : Intermediate


                
                    
def zfill(string, width=0):
    """
    Right-align a string within a given width by padding it with spaces on the left.
    """
    return string.zfill(width)                
              
Tags: