【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
    )
)

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

作者:x66ccff 原文地址:https://blog.csdn.net/qq_18846849/article/details/128621221

%s 个评论

要回复文章请先登录注册