You can use the zfill()
method to pad a string with zeros:
In [3]: str(1).zfill(2)
Out[3]: '01'
More Related Contents:
- How to use % symbol correctly
- String formatting: % vs. .format vs. f-string literal
- Display number with leading zeros
- How can I fill out a Python string with spaces?
- Python’s many ways of string formatting — are the older ones (going to be) deprecated?
- How can I format a decimal to always show 2 decimal places?
- Display a decimal in scientific notation
- What does %s mean in a Python format string?
- Format a datetime into a string with milliseconds
- What’s the difference between %s and %d in Python string formatting?
- String with ‘f’ prefix in python-3.6
- partial string formatting
- Format string unused named arguments [duplicate]
- Format strings vs concatenation
- Logging variable data with new format string
- Python TypeError: non-empty format string passed to object.__format__
- Nested f-strings
- When to use %r instead of %s in Python? [duplicate]
- How to implement conditional string formatting?
- How do I escape curly-brace ({}) characters in a string while using .format (or an f-string)?
- Python SQL query string formatting
- Plural String Formatting
- Most Pythonic way to print *at most* some number of decimal places [duplicate]
- Can Python’s logging format be modified depending on the message log level?
- Python 3 bytes formatting
- How to convert escaped characters? [duplicate]
- str.format() raises KeyError
- Python, print all floats to 2 decimal places in output
- Leaving values blank if not passed in str.format
- python format string thousand separator with spaces