在python中将代码用大变量名分割成两行

ris*_*p89 0 python coding-style

我想将python代码分成两行,我的代码类似于:

if long_named_three_d_array[first_dimension][second_dimension][third_dimension] == somevalue:
    //dosomething
Run Code Online (Sandbox Code Playgroud)

如果条件超过两行,我想分开.

请帮忙.谢谢.

Ign*_*ams 5

在Python中,LHS可以放在括号中.

>>> a = {}
>>> a[1] = {}
>>> a[1][2] = {}
>>> (a[1][2]
... [3]) = ''
>>> a
{1: {2: {3: ''}}}
>>> (b) = 2
>>> b
2
Run Code Online (Sandbox Code Playgroud)

这意味着您可以将您的行写为

if (long_named_three_d_array[first_dimension] 
    [second_dimension]
    [third_dimension] ) == somevalue:
# Rest of code here, obviously properly indented in for the if.
Run Code Online (Sandbox Code Playgroud)