Multiline code - trailing slash usage

Bruno Desthuilliers bruno.42.desthuilliers at
Thu Mar 15 16:23:12 CET 2007

abcd a écrit :
> When do I need to use a trailing slash to separate code over multiple
> lines.
> For example:
> x = "hello world, this is my multiline " + \
>      "string!!!!"

Here you don't need the +

> x = {'name' : \
>       'bob'}

And here you don't need the antislash

> Do I need to use the "\" in the above examples?  When do i need to use
> it?

IIRC, lists, tuples and dicts litterals, function args, list comps and 
generator expressions can span multiple lines. In any other case, you 
need the antislash. But you'd better check in the FineManual...

More information about the Python-list mailing list