If you are trying to print a string, what happens if you leave out one of the quotation marks or both and why?
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".
Comments
Leave a comment