String Padding Function

  • Share this:

Code introduction


This function is used to pad a string to a specified width, and if the length of the string is insufficient, it pads with the specified character on the left.


Technology Stack : String, rjust

Code Type : String Handling Function

Code Difficulty : Intermediate


                
                    
def zfill(string, width=0, fillchar=' '):
    return str(string).rjust(width, fillchar)                
              
Tags: