{"id":16174,"date":"2021-08-12T09:37:12","date_gmt":"2021-08-12T04:07:12","guid":{"rendered":"https:\/\/python-programs.com\/?p=16174"},"modified":"2021-11-22T18:38:26","modified_gmt":"2021-11-22T13:08:26","slug":"python-program-to-add-trailing-zeros-to-string","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-add-trailing-zeros-to-string\/","title":{"rendered":"Python Program to Add Trailing Zeros to String"},"content":{"rendered":"

In the previous article, we have discussed Python Program to Calculate GST<\/a>
\nGiven a String, and the task is to add the given number of trialing Zeros to the given String.<\/p>\n

ljust() method :<\/strong><\/p>\n

We can add trailing zeros to the string using the ljust() method. It has two parameters, x, and y, where x is the length of the string. What will this method accomplish? It will simply go through a string and then to the length of the string that we require, and if both are not the same, it will pad those zeros that they have passed through a string and then store them in another.<\/p>\n

Examples:<\/strong><\/p>\n

Example1:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given String = hello btechgeeks\r\nno of zeros to be added = 5<\/pre>\n

Output:<\/strong><\/p>\n

The above given string = hello btechgeeks\r\nThe above Given string with added given number of trailing zeros =  hello btechgeeks00000<\/pre>\n

Example1:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given String = good morning btechgeeks\r\nno of zeros to be added = 10<\/pre>\n

Output:<\/strong><\/p>\n

Enter some Random String = good morning btechgeeks\r\nThe above given string = good morning btechgeeks\r\nEnter some Random Number = 10\r\nThe above Given string with added given number of trailing zeros = good morning btechgeeks0000000000<\/pre>\n

Program to Add Trailing Zeros to String<\/h2>\n

Below are the ways to add trailing Zeros to the given String<\/p>\n

Method #1: Using ljust() Method (Static Input)<\/h3>\n

Approach:<\/strong><\/p>\n