How to use f-string (Python 6+) In Python
Python3
str = "GFG" n = 4 # print the original string print ( "The original string :" , str ) # add trailing zeros to the string str = f "{str}{'0'*n}" print ( "The string after adding trailing zeros :" , str ) |
Output
The original string : GFG The string after adding trailing zeros : GFG0000
Time complexity: O(n), where n is the length of the string.
Auxiliary Space: O(1)
Python | Add trailing Zeros to string
Sometimes, we wish to manipulate a string in such a way in which we might need to add additional zeros at the end of the string; in case of filling the missing bits or any other specific requirement. The solution to this kind of problem is always handy and is good if one has knowledge of it. Let’s discuss certain ways in which this can be solved.
Contact Us