Python Input/Output Double Quotes, Single Quotes Problem

Asked 1 weeks ago, Updated 1 weeks ago, 1 views

Results to output: "C:\Download\'hello'.py"

Error code:

print( ' \"C:\Download\\\'hello\'.py\" ')

Correct Code:

print( " \"C:\Download\\\'hello\'.py\" ")

Question 1. The difference between my code and the answer code is that I used ' at the front and back The correct code is just " (big quotation marks), but I don't know why there is an error when using small quotation marks

Question 2. Using three \ (backslashes) in Download\\ is not a good idea Do you put \ (backslash) and ' (small quotation marks) together, so do you put \ (backslash) in front of them? C:\ <-- I'm asking because I don't have to put \ (backslash) here!

There are still many things I don't know because I'm a beginner.

python

2022-09-20 15:42

1 Answers

Question 1. I don't know why there is an error when using a single quotation mark

The program that scores the correct answers probably handled the wrong answers, but I guess it was because unnecessarily double quotes were escaped.

print( ' \"C:\Download\\\'hello\'.py\" ')

# Both the code above and the code below output the same without errors.
# Take a good look at the difference.

print( ' "C:\Download\\\'hello\'.py" ')

Question 2. If you use three (backslashes), do you put (backslashes) in front of each (backslashes) because (small quotation marks) are attached together?

Yes.

If you number the three backslashes from the front, it looks like this.


2022-09-20 15:42

If you have any answers or tips


© 2022 pinfo. All rights reserved.