Sometimes, we wish to manipulate a string in such a way in which we might need to add additional K at the end of string in case of filling the missing bits or any other specific requirement. The solution to this kind of problems is always handy and is good if one has knowledge of it. Let’s discuss certain ways in which this can be solved.
Method #1 : Using
This task can be performed using the simple inbuilt string function of ljust in which we just need to pass N times required and the element to right pad, in this case being K.
The original string : GFG The string after adding trailing K : GFGMMMMM
Method #2 : Using
String formatting using the format function can be used to perform this task easily, we just mention the number of elements total, element needed to pad, and direction of padding, in this case right.
The original string : GFG The string after adding trailing K : GFG00000
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- Python - Append according to Kth character
- numpy.append() in Python
- append() and extend() in Python
- Python - Pandas dataframe.append()
- Python | Perform append at beginning of list
- Python | Pandas Index.append()
- Python | Pandas TimedeltaIndex.append()
- Python | Append multiple lists at once
- Python | Pandas Series.append()
- Python | Append at front and remove from rear
- Python | Append Odd element twice
- Python | Append String to list
- Python | Append suffix/prefix to strings in list
- Python append to a file
- Append to JSON file using Python
- Python - Conditional String Append
- numpy.ma.append() function | Python
- Python - Append Similar Values as Key
- Python - Append Multitype Values in Dictionary
- Difference Between '+' and 'append' in Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.