"%s" is being left adjusted to 7 places first - eg "%s ", and then you're substituting the '123456' for the %s... hence the result you get...

>>> '%s'.ljust(7)
'%s     '
>>> _ % '123456'
'123456     '

You could use:

>>> ('%s' % '123456').ljust(7)
'123456

Or specify appropriate width in the format string...

Answer from Jon Clements on Stack Overflow
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ ref_string_ljust.asp
Python String ljust() Method
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Practice Problems Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Training ... Note: In the result, there are actually 14 whitespaces to the right of the word banana. The ljust() method will left align the string, using a specified character (space is default) as the fill character.
๐ŸŒ
GitHub
github.com โ€บ renpy โ€บ renpy โ€บ issues โ€บ 2551
ljust() not working with rpy python 3 enabled ยท Issue #2551 ยท renpy/renpy
January 1, 2021 - The function ljust() applied to a string worked just fine until I tried the rpy python 3 feature. It throws the exception: TypeError: ljust() argument 2 must be char, not unicode (this probably affects too to str.rjust() and str.center()...
Author: renpy
๐ŸŒ
Tutorialspoint
tutorialspoint.com โ€บ python โ€บ string_ljust.htm
Python String ljust() Method
Then the remaining blank spaces on the right are filled with the specified character "0" as the fillchar argument using Python String ljust() method. The result is then retrieved: # Initializing the string str = "this is string example....wow!!!"; print (str.ljust(50, '0')) When we run above program, it produces following result: this is string example....wow!!!000000000000000000 ยท Following is an example where a new string of length 89 is generated and aligns the created string Programming to the left. Since the fillchar is not provided, the default value of blank space is used.
๐ŸŒ
Python
bugs.python.org โ€บ issue3446
Issue 3446: center, ljust and rjust are inconsistent with unicode parameters - Python tracker
This issue tracker has been migrated to GitHub, and is currently read-only. For more information, see the GitHub FAQs in the Python's Developer Guide ยท This issue has been migrated to GitHub: https://github.com/python/cpython/issues/47696
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ ljust() in python
ljust() in Python | ljust() Function in Python - Scaler Topics
May 31, 2022 - If the given width is the same or less than the length of the original string, the function will do nothing. It will just return the original string, as you can see above in the third example. ... The fillchar character must be a single character. If we give fillchar more than one character, ...
๐ŸŒ
Programiz
programiz.com โ€บ python-programming โ€บ methods โ€บ string โ€บ ljust
Python String ljust()
# example string string = 'cat' width = 5 fillchar = '*' # print left justified string print(string.ljust(width, fillchar)) ... Here, the string cat is aligned to the left, and the remaining two spaces on the right is filled with the character *. Note: If you want to right justify the string, use rjust().
Find elsewhere
๐ŸŒ
AskPython
askpython.com โ€บ python โ€บ string โ€บ python-string-ljust-rjust-functions
Python String ljust() and rjust() functions - AskPython
April 5, 2023 - The Python string ljust() function accepts characters for padding in an input string by adding it to the right of the input string.
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 12621907 โ€บ python-ljust-not-displaying-properly-when-including-a-lin
string - Python ljust not displaying properly when including a lin - Stack Overflow
You realize the whole anchor tag in the_team variable is being justified and not just the value of row.name right? It would help to see the unexpected output though. ... Right, if I include the anchor tag in the output line around the %s for team name, it will include the entire line including the spaces added by ljust.
๐ŸŒ
Toppr
toppr.com โ€บ guides โ€บ python-guide โ€บ references โ€บ methods-and-functions โ€บ methods โ€บ string โ€บ ljust โ€บ python-string-ljust
Python ljust() function | Why do we use Python String ljust() function? |
September 27, 2021 - In the above example, considering the first print statement, txt.ljust(10) generates a new string of length 10 and aligns โ€˜Pythonโ€™ to the left. Because a fillchar is not specified, the default value space is utilized.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python-string-ljust-rjust-center
Python String - ljust(), rjust(), center() - GeeksforGeeks
January 2, 2025 - The return type of ljust() is a new string that is left-justified with padding.
๐ŸŒ
Codecademy
codecademy.com โ€บ docs โ€บ python โ€บ strings โ€บ .ljust()
Python | Strings | .ljust() | Codecademy
November 26, 2023 - Note: .ljust() returns a new string and does not modify the original string. Only one specific character can be mentioned to fill the remaining part of the string with the parameter fillchar. The code below is runnable, change the value of exampleString, example_length, and example_character to test the .ljust() method. ... Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 58759256 โ€บ ljust-on-strrow-has-no-outcome
python - ljust on str(row) has no outcome - Stack Overflow
Doing it on row directly (row.ljust(6)) gives me AttributeError: 'list' object has no attribute 'ljust' Changing the value (20 instead of 6) doesn't change anything rjust(); center() also don't work It works on other strings, just like the center string above
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ string-rjust-ljust-python
String rjust() and ljust() in python() | GeeksforGeeks
January 8, 2018 - If it's not provided, space is taken as a default argument. Returns: Returns a new string of given length after substituting a given character in right side of original string. Example 1 ... # example string string = 'geeks' length = 8 # If no fill character is provided, space # is used as fill character. print(string.ljust(length)) Output: (Three spaces are printed after geeks)
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-string-ljust-method
Python String ljust() Method - GeeksforGeeks
July 23, 2025 - The ljust() method can be used without specifying a fillchar, in which case it defaults to a space.