[Tutor] about \

Hugo González Monteverde hugonz-lists at h-lab.net
Mon Oct 24 16:59:01 CEST 2005


Hi,

The '\' character is used to break lines and ask the interpreter to 
treat them as a single line, but Python is smart enough to allow 
breaking lines inside parenthesis and braces...so:

NOT WORKING:

 >>> a, e, i, o, u = 1, 2,
Traceback (most recent call last):
   File "<stdin>", line 1, in ?
ValueError: unpack tuple of wrong size
 >>>                 3, 4, 5
   File "<stdin>", line 1
     3, 4, 5
     ^
SyntaxError: invalid syntax

WORKS:

 >>> (a, e, i, o, u) = (1, 2,
...                   3, 4, 5)
 >>>


What's the difference? The parenthesis... the interpreter sees the open 
parenthesis and assumes correctly that the line is not yet finished.

Hugo

Shi Mu wrote:
> Is there any difference if I remove the '/'
> from the following statement?
> intMatrix2 = [[1,1,2,4,1,7,1,7,6,9],\
>              [1,2,5,3,9,1,1,1,9,1],\
>              [0,0,5,1,1,1,9,7,7,7]]
> print intMatrix2
> I removed one '\' and it still works.
> So what is the use of '\'?
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 


More information about the Tutor mailing list