str.zfill()
str.zfill() is a Python method in the String Methods category. Pads the string on the left with zeros to reach the specified width. The syntax is str.zfill(width). Parameters: width — target length. Returns: Zero-filled string. A typical example: "42".zfill(5) # "00042"
"-42".zfill(5) # "-0042". A close sibling is str.upper(), which returns a copy of the string with all characters converted to uppercase. A close sibling is str.lower(), which returns a copy of the string with all characters converted to lowercase. A close sibling is str.capitalize(), which returns a copy with the first character capitalized and the rest lowercased. A close sibling is str.title(), which returns a titlecased version where each word starts with uppercase. More about this category: String methods for text manipulation — split, join, replace, format, and more. For a broader walkthrough, read the String Methods guide. Related String Methods entries: str.upper(), str.lower(), str.capitalize(), str.title(), str.strip(), str.lstrip().