在python中缩短变量

2024-05-13 21:59:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图缩短我的变量,使其少于79个字符。我该怎么做呢?你知道吗

movies = [force_awakens, new_hope, rogue_one, last_jedi, empire, return_of_the_jedi]

Tags: ofthenewreturnmoviesoneempirelast
1条回答
网友
1楼 · 发布于 2024-05-13 21:59:16

您可以将变量缩短到少于79个字符,也可以使用括号将其拆分为多行。你知道吗

The preferred way of wrapping long lines is by using Python's implied line continuation inside parentheses, brackets and braces. Long lines can be broken over multiple lines by wrapping expressions in parentheses. These should be used in preference to using a backslash for line continuation.

您可以查看PEP-8样式指南here

但是,如果您真正想要的只是缩短变量,可以尝试为变量选择一个较小的名称,或者删除每个逗号后面的空格。该行的当前长度是84,删除逗号将使其精确到79。这将使代码有点难看,但它会为你做的工作。你知道吗

我希望这有帮助。你知道吗

相关问题 更多 >