Splitting numeric litterals

MRAB python at mrabarnett.plus.com
Wed Jul 14 22:02:06 EDT 2010


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, compare :
> 
>  >>> "1000\
> ... 000\
> ... 000"
> '1000000000'
>  >>> 1000\
> ... 000\
>   File "<stdin>", line 2
>     000\
>       ^
> SyntaxError: invalid syntax
>  >>>
> 
> 
> Is this the general behaviour ? So, how do you edit code containing a 
> very very long numeric constant ?

Normally it's only string literals that could be so long that you might
want to split them over several lines. It is somewhat unusual to have a
_numeric_ literal that's very very long!

For an integer literal you could use a string literal and convert it to
an integer:

 >>> int("1000\
000\
000")
1000000000
 >>>



More information about the Python-list mailing list