On 08/05/13 21:31, Alok Nayak wrote:
I asked this question here,
http://stackoverflow.com/questions/16435233/this-python-string-literals-documentation-couldnt-explain-me-single-quote-pres,
. I was advised to ask here


They were wrong. It is not relevant here, since it is not a question about 
development of Python. But I will answer your question anyway.

The relevant parts of the documentation are:

shortstring     ::=  "'" shortstringitem* "'" | '"' shortstringitem* '"'
shortstringitem ::=  shortstringchar | escapeseq
shortstringchar ::=  <any source character except "\" or newline or the quote>

So let's look at a string:

'a"b'

This is a shortstring, made up of single-quote followed by three 
shortstringitems, followed by single-quote. All three shortstring items are 
shortstringchar, not escapeseq:

a is a source character, not including "\" or newline or single-quote
" is a source character, not including "\" or newline or single-quote
b is a source character, not including "\" or newline or single-quote


[...]
shortstringchar ::=  <any source character except "\" or newline or the quote>

  here in this definition 'the quote' isn't specific whether single (') or
double (").

Correct. You are expected to understand that it means either single-quote or 
double-quote according to context.

This is documentation aimed at a human reader who should be able to use human reasoning 
skills to understand what "the quote" means, it is not the literal BNF grammar 
used by the compiler to compile Python's parser. For brevity and simplicity, some 
definitions may be simplified.



--
Steven
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to