Splitting numeric litterals

Steven D'Aprano steve-REMOVE-THIS at cybersource.com.au
Wed Jul 14 21:57:25 EDT 2010


On Thu, 15 Jul 2010 03:30:24 +0200, candide wrote:

> The escape sequence \ENTER allows to split a string over 2 consecutive
> lines. On the other hand, it seems impossible to split a numeric
> litteral across multiple lines
[...]
> Is this the general behaviour ? 

Yes. You can't put any whitespace in the middle of a numeric literal:


>>> n = 4 2
  File "<stdin>", line 1
    n = 4 2
          ^
SyntaxError: invalid syntax



> So, how do you edit code containing a very very long numeric constant ?



s = (
    "1234567890123456789012345678901234567890"
    "1234567890123456789012345678901234567890"
    "1234567890123456789012345678901234567890"
    "1234567890123456789012345678901234567890"
    "1234567890123456789012345678901234567890"
    )
assert len(s) == 200
n = int(s)



-- 
Steven



More information about the Python-list mailing list