Last answered:

30 Mar 2020

Posted on:

28 Mar 2020

0

Why does my print get erased?

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 answers ( 0 marked as helpful)
Instructor
Posted on:

30 Mar 2020

0
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

Submit an answer