Kiran Varghese Kiran Varghese - 27 days ago 7
Python Question

Why do these two command give different outputs?

Command 1:

subprocess.call(["echo","\"hw\""])


Output:

"hw"


Command2 :

subprocess.call(["echo","""hw"""])


Output:

hw

Answer

Your first command passes the quotes to the echo system command, and thus is equivalent to doing this on the command line:

$ echo "hw"

Your second command only passes the hw string (no quotes) to echo and is equivalent to the following:

$ echo hw

In your second command, you're using the docstring notation for strings, which is equivalent to "hw" as well as 'hw'.

Comments