{"id":3676,"date":"2022-12-02T18:25:41","date_gmt":"2022-12-02T18:25:41","guid":{"rendered":"https:\/\/gyanipandit.com\/programming\/?p=3676"},"modified":"2022-12-02T18:25:42","modified_gmt":"2022-12-02T18:25:42","slug":"python-string-ljust","status":"publish","type":"post","link":"https:\/\/gyanipandit.com\/programming\/python-string-ljust\/","title":{"rendered":"Python String ljust() Method With Example"},"content":{"rendered":"<p style=\"text-align: center;\">Python String ljust<\/p>\n<p>Now, we are going to learn about the ljust method. With this method, we get our string as left justified, in a string of length width, which is provided as an argument to the ljust method. Padding is done using the specified padding character (if not specified, it defaults to whitespace). Let\u2019s have a look at a simple example, which demonstrates the same thing.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-3681 size-full\" src=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-ljust-METHOD.jpg\" alt=\"\" width=\"638\" height=\"82\" srcset=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-ljust-METHOD.jpg 638w, https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-ljust-METHOD-300x39.jpg 300w\" sizes=\"auto, (max-width: 638px) 100vw, 638px\" \/><\/p>\n<h2 style=\"text-align: center;\">Python String ljust() Method<\/h2>\n<p>As you can see in the above program, we have a string, and then we are trying to call the ljust method on the string. The width is given as an argument to the method, which is 20 in our case, and we also have specified a padding character, which is &#8216;@&#8217; in our case. So, the string that we get as a return value from the ljust method is a left justified string with length 20 in our case, which is the width, and the padding is done by the specified padding character.<\/p>\n<p>Let\u2019s have a look at the output now &#8211;<\/p>\n<p>GyaniPandit@@@@@@@@@<\/p>\n<p>As you can see in the output, we have a left-justified string, with a length of 20, and the padding is done with the padding character.<\/p>\n<p>If the width that we provide as an argument to the ljust method is less than or equal to the length of the string, then the original string is returned. Let\u2019s have a look at the example, which demonstrates the same thing.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-3682 size-full\" src=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-ljust-METHOD-1-1.jpg\" alt=\"\" width=\"624\" height=\"71\" srcset=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-ljust-METHOD-1-1.jpg 624w, https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-ljust-METHOD-1-1-300x34.jpg 300w\" sizes=\"auto, (max-width: 624px) 100vw, 624px\" \/><\/p>\n<p>As you can see in the above program, we again have the string, and then we are again calling the ljust method. This time, the width which is passed is less than the length of the string. In such a situation, the return value from the method is the same string.<\/p>\n<p>So, as and when required, we can make use of the ljust method, which returns the left justified string of the length, which is given as an argument to the method.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python String ljust Now, we are going to learn about the ljust method. With this method, we get our string as left justified, in a string of length width, which is provided as an argument to the ljust method. Padding is done using the specified padding character (if not specified, it defaults to whitespace). Let\u2019s [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25],"tags":[26,27],"class_list":{"0":"post-3676","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-python-tutorial","7":"tag-python","8":"tag-python-tutorial"},"_links":{"self":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/3676","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/comments?post=3676"}],"version-history":[{"count":4,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/3676\/revisions"}],"predecessor-version":[{"id":4189,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/3676\/revisions\/4189"}],"wp:attachment":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/media?parent=3676"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/categories?post=3676"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/tags?post=3676"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}