Code :
a = "240"
print(a.zfill(4))
Solution and Explanation :
The zfill() method in Python is used to pad a string with zeros (0) on the left side until the string reaches the specified width. In your case, you've specified a width of 4.
Here's how it works:
a = "240"
result = a.zfill(4)
print(result)
Output:
0240
In this example, the original string "240" has a length of 3. The zfill(4) method pads zeros on the left side to make the length of the string 4. Therefore, the result is "0240".
0 Comments:
Post a Comment