I've started learning Python recently and I don't understand why Python behaves like this:
>>> "OK" 'OK' >>> """OK""" 'OK' >>> "not Ok' File "<stdin>", line 1 "not Ok' ^ SyntaxError: EOL while scanning string literal >>> "not OK""" 'not OK'
Why doesn't it give an error for the last statement as the number of quotes does not match?
The final """
is not recognized as a triple-quotation, but a single "
(to close the current string literal) followed by an empty string ""
; the two juxtaposed string literals are concatenated. The same behavior can be more readily recognized by putting a space between the closing and opening "
.
>>> "not OK" ""
'not OK'
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments