如何在Python字典中正确设置长字符串的格式

如何在Python字典中正确设置长字符串的格式,python,python-3.x,dictionary,formatting,Python,Python 3.x,Dictionary,Formatting,您可以想象,我正在开始使用Python(对于noob问题感到抱歉)。我正在编写一个使用一些长字典条目的代码,我正在努力使Python满足80个字符的限制 这是我字典的一小段: "Hybrid functionals": { "B1LYP": "The one - parameter hybrid functional with Becke '88 exchange and Lee - Yang - Parr correlation(25 % HF exchange)", "B3L

您可以想象,我正在开始使用Python(对于noob问题感到抱歉)。我正在编写一个使用一些长字典条目的代码,我正在努力使Python满足80个字符的限制

这是我字典的一小段:

"Hybrid functionals": {
    "B1LYP": "The one - parameter hybrid functional with Becke '88 exchange and Lee - Yang - Parr correlation(25 % HF exchange)",
    "B3LYP and B3LYP/G": "The popular B3LYP functional (20% HF exchange) as defined in the TurboMole program system and the Gaussian program system, respectively",
    "O3LYP": "The Handy hybrid functional",
    "X3LYP": "The Xu and Goddard hybrid functional",
    "B1P": "The one-parameter hybrid version of BP86",
    "B3P": "The three-parameter hybrid version of BP86",
    "B3PW": "The three-parameter hybrid version of PW91",
    "PW1PW": "One-parameter hybrid version of PW91",
    "mPW1PW": "One-parameter hybrid version of mPWPW",
    "mPW1LYP": "One-parameter hybrid version of mPWLYP",
    "PBE0": "One-parameter hybrid version of PBE",
    "PW6B95": "Hybrid functional by Truhlar",
    "BHANDHLYP": "Half-and-half hybrid functional by Becke"},
那么,在字典中处理超长字符串的正确方法是什么呢


谢谢大家

Python本身并不在乎;您收到的是警告,而不是错误,因为您没有遵守正确的格式。如果要修复此问题,请尝试按enter键拆分该行

如果你有一个非常大的字典,考虑把它放在一个文本文件中并在需要时阅读它。

Python没有“80字符限制”。这是一个风格建议,但你可以不尊重它。但是,它会使代码更难阅读,并且编辑器可能会警告您这些长行

解决此问题的一种方法是使用:

多个相邻字符串或字节文字(由空格分隔), 可能使用不同的引用约定,并且 含义与它们的连接相同。因此,“你好”‘世界’是 相当于“helloworld”

所以,你可以把你的口述写成:

{
    "B1LYP": "The one - parameter hybrid functional with Becke '88" 
             " exchange and Lee - Yang - Parr correlation(25 % HF " 
             "exchange)",
    ...

你的老板在抱怨,还是你的线人在抱怨?谢谢你善意的回答。谢谢你的提示,我的朋友。