Print "n" or newline characters as part of the output on terminal
Question:
I’m running Python on terminal
Given a string string = "abcdn"
I’d like to print
it somehow so that the newline characters 'n'
in abcdn
would be visible rather than go to the next line
Can I do this without having to modify the string and adding a double slash (\n
)
Answers:
Use repr
>>> string = "abcdn"
>>> print(repr(string))
'abcdn'
If you’re in control of the string, you could also
use a ‘Raw’ string type:
>>> string = r"abcdn"
>>> print(string)
abcdn
Another suggestion is to do that way:
string = "abcdn"
print(string.replace("n","\n"))
But be aware that the print function actually print to the terminal the “n”, your terminal interpret that as a newline, that’s it. So, my solution just change the newline in + n
Input: "a,b,c,en1,2,3,4n" && ","
Output:
Return Value: [["a", "b", "c", "e"], ["1", "2", "3", "4"]]
How can do it? Help please!
I’m running Python on terminal
Given a string string = "abcdn"
I’d like to print
it somehow so that the newline characters 'n'
in abcdn
would be visible rather than go to the next line
Can I do this without having to modify the string and adding a double slash (\n
)
Use repr
>>> string = "abcdn"
>>> print(repr(string))
'abcdn'
If you’re in control of the string, you could also
use a ‘Raw’ string type:
>>> string = r"abcdn"
>>> print(string)
abcdn
Another suggestion is to do that way:
string = "abcdn"
print(string.replace("n","\n"))
But be aware that the print function actually print to the terminal the “n”, your terminal interpret that as a newline, that’s it. So, my solution just change the newline in + n
Input: "a,b,c,en1,2,3,4n" && ","
Output:
Return Value: [["a", "b", "c", "e"], ["1", "2", "3", "4"]]
How can do it? Help please!