python turn non printable character to escape string

text_to_print = repr(text_with_newlines_and_other_things)
print(text_to_print)

# example
>>> print("hi\nthere")
hi
there
>>> print(repr("hi\nthere")) 
'hi\nthere'

Here is what the above code is Doing:
1. It’s creating a string variable called text_with_newlines_and_other_things.
2. It’s printing the string to the console.
3. It’s creating a new string variable called text_to_print.
4. It’s setting the value of text_to_print to the string representation of text_with_newlines_and_other_things.
5. It’s printing the string representation of text_with_newlines_and_other_things to the console.

The output of the code is:

hi
there
‘hi\nthere’

As you can see, the string representation of text_with_newlines_and_other_things includes the newline characters.