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)
oh! this happened in Spyder in case it changes anything
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.
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.
Thanks Eli! That was very helpful.