簡體   English   中英

一組Python引用的雙引號?

[英]A Single Set of Double Quotes for Python Comments?

在審查edX.org上的在線CS188.1x類中使用的一些代碼(由教師編寫的代碼)時,我注意到重復使用一組雙引號(如可能在str附近使用)用作注釋。

我之前沒有見過這個,也沒有在PEP8中提到我能找到的,但它似乎確實很好。 任何人都可以開導我嗎?

這是一個例子:

class SomeClass():
    """
    Some docstring info, using standard 'triple double quotes'
    """
    def  __init__(self):
        "This is the comment style to which I'm referring."
        some.code = foo      # Here's a normal inline comment

    def bar(self, item):
        "Here is another example of the comment style"
       return wtf

docstring是任何字符串文字,它作為類,方法,函數或模塊中的第一個語句出現。 在風格上,使用三重引號格式以允許更長,更好格式化的文檔字符串,並引起對它們的注意以便於參考,但是任何字符串都符合條件。

文檔字符串與注釋不同,因為注釋與程序的執行完全無關,而文檔字符串在運行時通過訪問對象的__doc__變量可用。

那只是文檔。 這是一個很好的設計建議。 例如,如果你在python shell中加載該類,你可以調用一個help(bar) ,你會得到"Here is another example of the comment style"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM