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 '\'?
You only need line continuations if you aren't inside brackets, braces or parentheses. Inside these paired delimiters Python assumes you know what you are doing and will continue the statement or expression on the next line. >>> print "This is a continued"\ ... " statement" This is a continued statement >>> Note that Python *knew* the statement was complete at the end of the second line. Inside an extended string literal (""" or ''') it has the effect of removing the newline that would otherwise appear in the string. >>> print repr("""This string has a ... newline in it""") 'This string has a\nnewline in it' >>> print repr("""There is no \ ... newline in this string""") 'There is no newline in this string' >>> regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list