Why doesn't Python give any error when quotes around a string do not match?

W. R.
:

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?

chepner
:

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Why doesn't the compiler give an error when an uninitialized variable is returned?

From Dev

Why does =:= give an error when the variable is not instantiated, but == doesn't?

From Dev

Why doesn't this method give any output?

From Dev

Why doesn't this give redeclaration error?

From Dev

Why doesn't this give compilation error?

From Dev

Why doesn't this std::string C++ code give compile-time error?

From Dev

Why does command prompt give me an error code in compilation when my IDE doesn't?

From Dev

Memory access violation doesn't give any error in c

From Dev

Why doesn't this program echo any string?

From Dev

Why doesn't this program echo any string?

From Dev

Why is my string matching something in an array when that string doesn't contain any of those characters?

From Dev

Why str(reversed(...)) doesn't give me the reversed string?

From Dev

Regex to match any string between quotes

From Dev

Why doesn't glob:* match any path in PathMatcher?

From Dev

Why doesn't this regex match in ruby but matches in any other language?

From Dev

Parse OS X SDK doesn't work (and doesn't give any error)

From Dev

Why doesn't String.match() produce expected results when a global flag is present?

From Dev

Why does preg_match doesn't find a string between tags when regex is OK?

From Dev

Fatal error when using scripts through virtualenv - extra quotes around python.exe

From Dev

Why there are no quotes when using dictionary based string formatting in Python?

From Dev

why doesn't python return result using regex when there's more than one match?

From Dev

SPARQL query doesn't give any results

From Dev

Grunt doesn't give any output [Ubuntu]

From Dev

DbContext doesn't give any data

From Dev

Why printf("test"); does not give any error?

From Dev

Why printf("test"); does not give any error?

From Dev

Why doesn't the regex ^([0|1]1)+$ match the string "111"?

From Dev

Bash: Why doesn't * return empty string in case of no match

From Dev

Why doesn't this JavaScript object key match a string with the same name?

Related Related

  1. 1

    Why doesn't the compiler give an error when an uninitialized variable is returned?

  2. 2

    Why does =:= give an error when the variable is not instantiated, but == doesn't?

  3. 3

    Why doesn't this method give any output?

  4. 4

    Why doesn't this give redeclaration error?

  5. 5

    Why doesn't this give compilation error?

  6. 6

    Why doesn't this std::string C++ code give compile-time error?

  7. 7

    Why does command prompt give me an error code in compilation when my IDE doesn't?

  8. 8

    Memory access violation doesn't give any error in c

  9. 9

    Why doesn't this program echo any string?

  10. 10

    Why doesn't this program echo any string?

  11. 11

    Why is my string matching something in an array when that string doesn't contain any of those characters?

  12. 12

    Why str(reversed(...)) doesn't give me the reversed string?

  13. 13

    Regex to match any string between quotes

  14. 14

    Why doesn't glob:* match any path in PathMatcher?

  15. 15

    Why doesn't this regex match in ruby but matches in any other language?

  16. 16

    Parse OS X SDK doesn't work (and doesn't give any error)

  17. 17

    Why doesn't String.match() produce expected results when a global flag is present?

  18. 18

    Why does preg_match doesn't find a string between tags when regex is OK?

  19. 19

    Fatal error when using scripts through virtualenv - extra quotes around python.exe

  20. 20

    Why there are no quotes when using dictionary based string formatting in Python?

  21. 21

    why doesn't python return result using regex when there's more than one match?

  22. 22

    SPARQL query doesn't give any results

  23. 23

    Grunt doesn't give any output [Ubuntu]

  24. 24

    DbContext doesn't give any data

  25. 25

    Why printf("test"); does not give any error?

  26. 26

    Why printf("test"); does not give any error?

  27. 27

    Why doesn't the regex ^([0|1]1)+$ match the string "111"?

  28. 28

    Bash: Why doesn't * return empty string in case of no match

  29. 29

    Why doesn't this JavaScript object key match a string with the same name?

HotTag

Archive