I am learning python and i'm trying to add 2 ** in front of each line of some example text. However when i call ljust(2,'*') on every element it doesn't change the original string. I want to replace the new element with this old string but how?
This is what i' ve tried. First i tried it with a regular for loop but that didn't work. Then i came across a question where list comprehensions are explained Perform a string operation for every element in a Python list so i tried that.
This is what i have now
example_string = '''hello there how are you doing!
i am doig well thank you
lets get to work!!! '''
def modify_example_string():
global example_string
new_string_list = [element.ljust(2,'*') for element in example_string.split('\n')]
example_string = '\n'.join(new_string_list)
print(new_string_list)
modify_example_string()
This should return a new list with all the ljust transformations but it doesn't so i would like to know the proper way of solving this.