Answer to Question #328312 in Python for Robert

Question #328312

If you are trying to print a string, what happens if you leave out one of the quotation marks or both and why?

1
Expert's answer
2022-04-14T06:16:00-0400

Hello! If you leave out one of the quotation marks you will see an "EOL while scanning string literal" error.

print("Hello, world)

it happens because Python try to find out the second quotation mark, go to the end of the line and don't find it. (If you leave out the first quotation mark, the result will be the same)


If you leave out both quotation marks...

print(Hello, world)

...you will see another error : "NameError: name 'Hello' is not defined". It happens because without quotation marks, Python interpret your string as the variable with the appropriate name. In some cases, if you leave out both quotation marks, you could not see any mistakes, because, for example you already have a variable with name that you try to print.

Hello = "123"
print(Hello) #we want to print string "Hello"

In this case, the program will work correctly and will print "123".


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS