It seems like you misunderstood what ljust(2, '*') is doing. It does not add two * to the beginning of the string but will pad the string with * to a total length of 2. All your lines are longer, so it does nothing.
Instead, just use "**" + line to add the stars to the lines.
def modify_example_string():
global example_string
example_string = "\n".join("**" + line for line in example_string.splitlines())
Also, instead of using global I'd recommend using parameters and return values:
def prepend_stars(s):
return "\n".join("**" + line for line in s.splitlines())
example_string = prepend_stars(example_string)
The ljust method doesn't do what you expect. The documentation says:
Return the string left justified in a string of length width. Padding is done using the specified fillchar (default is an ASCII space). The original string is returned if width is less than or equal to len(s).
Your list comprehension is correct.
One solution might be to use format. A good tutorial here.
Example code with format:
example_string = '''hello there how are you doing!
i am doig well thank you
lets get to work!!! '''
def modify_example_string(example_string, ch, n):
new_string_list = ["{} {}".format(ch * n, element)
for element in example_string.split('\n')]
example_string = '\n'.join(new_string_list)
return example_string
print(modify_example_string(example_string, "*", 2))
# ** hello there how are you doing!
# ** i am doig well thank you
# ** lets get to work!!!