Search code examples
pythonstringshellsyntax-errorquotation-marks

SyntaxError: invalid syntax (when running python code from shell)


In Jupyter Notebook my Code runs fine, but when I run it from shell i get a syntax error at this part of my code:

res = f'"x"'+" "+f'"y"'+" "+f'"t"'+" "+f'"id"'+" "+f'"id2"'
           ^
SyntaxError: invalid syntax

However I need the String res to look like:

""x" "y" "t" "id" "id2""

I guess that the way i create it is causing the error.

Is there any other way to create a String containing quotation marks? Or anything to get rid of the syntax error? Thanks!


Solution

  • Got the answer now:

    res= "\"x\" \"y\" \"t\" \"id\" \"id2\""
    

    works for Shell as well as Python