The 365 Data Science team is proud to invite you to our own community forum. A very well built system to support your queries, questions and give the chance to show your knowledge and help others in their path of becoming Data Science specialists.
Ask
Anybody can ask a question
Answer
Anybody can answer
Vote
The best answers are voted up and moderated by our team

Why does my print get erased?

Why does my print get erased?

0
Votes
1
Answer

Hello!
I’m currently doing the Pyhton Bootcamp. I’m in the “Print” lesson. I tried to coding the home work and i did it like this:
print (“one, \’two\’, \”three\”, four, \five\ \n\tonce, \’i\’ caught a n\fish t\t\\’//alive\\\\'”)
The correcto one was (  print (“one, \’two\’, \”three\”, four, \\five\ \n\tonce, \’i\’ caught a n\ fish \n\t\t\’//alive\\\\'”)  )
 
I see that there are differences, but my question is, why is it that when I run the first option the answer shows up for less than a second and then it gets erased? (no error message or anything)
 
Thanks!!
 
oh! this happened in Spyder in case it changes anything

1 Answer

365 Team
0
Votes

Hi Maria, 
Thanks for reaching out! 
In Python the \ is an escape character, which can be used with other characters which have special meaning in Python. For instance, 
\’ or \” produce inverted single or double commas. Here is a link to the Python’s documentation, where all the variations are listed.
https://docs.python.org/2.0/ref/strings.html
The issue is because of the \five\ and n\fish. \f is a page-breaking character, which is used in printing. It forces the printer to eject the current page and start printing at the top of a new one. In Spyder this is what’s causing a new line in your console.
If you type \\five\ and n\ fish(add a space between n\ and fish) instead you should be able to see your print.
 
Best, 
Eli

Thanks Eli! That was very helpful.