【python】利用圆括号进行优雅的换行

在 Python 中,一般可以使用圆括号来进行长句子的换行。例如:

loss_align = (torch.sum(((torch.mean(z_mean_binary, dim=0) + torch.mean(z_mean_unary, dim=0))
                      / 2 - torch.mean(z_mean_leaf, dim=0)) ** 2))

或者:

loss_align = torch.sum(
    ((torch.mean(z_mean_binary, dim=0) + torch.mean(z_mean_unary, dim=0))
     / 2 - torch.mean(z_mean_leaf, dim=0)) ** 2
)

或者:

loss_align = (
    torch.sum(
        ((torch.mean(z_mean_binary, dim=0) + torch.mean(z_mean_unary, dim=0))
         / 2 - torch.mean(z_mean_leaf, dim=0)) ** 2
    )
)

如果要使用圆括号来进行换行,那么新一行的开头就要缩进与上一行相同的级别。

你可能感兴趣的:(python,深度学习,人工智能)