How can I do a line break (line continuation) in Python?

后端 未结 11 1583
囚心锁ツ
囚心锁ツ 2020-11-21 22:56

I have a long line of code that I want to break up among multiple lines. What do I use and what is the syntax?

For example, adding a bunch of strings,



        
11条回答
  •  北恋
    北恋 (楼主)
    2020-11-21 23:36

    One can also break the call of methods (obj.method()) in multiple lines.

    Enclose the command in parenthesis "()" and span multiple lines:

    > res = (some_object
             .apply(args)
             .filter()
             .values)
    

    For instance, I find it useful on chain calling Pandas/Holoviews objects methods.

提交回复
热议问题