Escape character in Lambda

#join column 
combine_lambda = lambda row: \
    '{} - {}'.format(row.product_type,
                     row.product_description)

I noticed there will be an error if without “\”.
Can anybody help me how does “\” work here. :grinning:

It’s a line break character than allows for a single logical line to be written over multiple lines. A very simple example-

x = \
3

Writing that without \ would lead to errors being thrown.

As an aside that seems like an odd way to use lambda, assigning it to a name and multiple lines kinda spoils the point. Would a normal function not do the job?

2 Likes

This is a great response by @tgrtim! :slight_smile:

I wanted to add that this idea of adding a \ is especially important in Python if you want the same idea of code to span several lines, because whitespace matters significantly in Python.