
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
What is zfill() method in Python?
The zfill method is built for left padding zeros in a string. For example:
>>> '25'.zfill(6) '000025'
We can also use the rjust(width[, fillchar]) method in string class that right justifies the string and pads the left side with given filler char. The default filler char is space but we can provide it '0' as well. You can use it as follows:
>>> '25'.rjust(6, '0') '000025'
We can also use Python string formatting to achieve this result as follows:
>>> print "%06d" % 25 '000025'
- Related Articles
- What is random.uniform method in Python?
- What is weekday() method in python?
- What is prmonth() method in python?
- What is Python commit() method in MySQL?
- What is the rollback() method in Python MySQL?
- What is usage of update method in Python dictionary?
- What is the groups() method in regular expressions in Python?
- What is the most efficient string concatenation method in python?
- What is the fetchone() method? Explain its use in MySQL Python?
- What does method time.tzset() do in Python?
- What does an object() method do in Python?
- What is the difference between operator and method on Python set?
- What is method overloading in Java?
- What is jQuery.ajaxSetup() method in jQuery?
- What is Number.toExponential() method in JavaScript?

Advertisements