第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

三引號字符串注釋崩潰簡單的python程序

三引號字符串注釋崩潰簡單的python程序

忽然笑 2021-12-09 16:00:17
當(dāng)我嘗試向我的代碼添加注釋時,我發(fā)現(xiàn)了這個奇怪的問題。我使用三重引號字符串進(jìn)行注釋,但程序因出現(xiàn)以下錯誤而崩潰:IndentationError: unexpected indent當(dāng)我#用來注釋三重引號字符串時,一切正常。有誰知道這個錯誤背后的原因以及我如何解決它?我的代碼:#This programs show that comments using # rather than """ """def main():    print("let's do something")#Try using hashtag to comment this block to get code working'''    Note following block gives you a non-sense indent error    The next step would be to consider how to get all the words from spam and ham    folder from different directory. My suggestion would be do it twice and then    concentrate two lists    Frist think about the most efficient way    For example, we might need to get rid off the duplicated words in the beginning    The thoughts of writing the algorithem to create the dictionary    Method-1:    1. To append all the list from the email all-together    2. Eliminate those duplicated words    cons: the list might become super large    I Choose method-2 to save the memory    Method-2:    1. kill the duplicated words in each string    2. Only append elements that is not already in the dictionary    Note:    1. In this case, the length of feature actually was determined by the    training cohorts, as we used the different English terms to decide feature    cons: the process time might be super long'''    def wtf_python(var1, var2):        var3 = var1 + var2 + (var1*var2)        return var3    wtfRst1 = wtf_python(1,2)    wtfRst2 = wtf_python(3,4)    rstAll = { "wtfRst1" : wtfRst1,               "wtfRst2" : wtfRst2    }    return(rstAll)if __name__ == "__main__":    mainRst = main()    print("wtfRst1 is :\n", mainRst['wtfRst1'])    print("wtfRst2 is :\n", mainRst['wtfRst2'])
查看完整描述

3 回答

?
桃花長相依

TA貢獻(xiàn)1860條經(jīng)驗(yàn) 獲得超8個贊

罪魁禍?zhǔn)祝?/p>


移動函數(shù)定義內(nèi)的注釋:


原因:


由于三引號字符串是有效的 python exp,它們應(yīng)該被同樣對待,即在函數(shù)作用域內(nèi)。


因此:


def main():

    print("let's do something")

    #Try using hashtag to comment this block to get code working

    '''

        Note following block gives you a non-sense indent error

        The next step would be to consider how to get all the words from spam and ham

        folder from different directory. My suggestion would be do it twice and then

        concentrate two lists


        Frist think about the most efficient way

        For example, we might need to get rid off the duplicated words in the beginning


        The thoughts of writing the algorithem to create the dictionary


        Method-1:

        1. To append all the list from the email all-together

        2. Eliminate those duplicated words


        cons: the list might become super large


        I Choose method-2 to save the memory

        Method-2:

        1. kill the duplicated words in each string

        2. Only append elements that is not already in the dictionary


        Note:

        1. In this case, the length of feature actually was determined by the

        training cohorts, as we used the different English terms to decide feature


        cons: the process time might be super long

    '''

    def wtf_python(var1, var2):

        var3 = var1 + var2 + (var1*var2)

        return var3


    wtfRst1 = wtf_python(1,2)

    wtfRst2 = wtf_python(3,4)


    rstAll = { "wtfRst1" : wtfRst1,

               "wtfRst2" : wtfRst2

    }

    return(rstAll)


if __name__ == "__main__":

    mainRst = main()

    print("wtfRst1 is :\n", mainRst['wtfRst1'])

    print("wtfRst2 is :\n", mainRst['wtfRst2'])

輸出:


let's do something

wtfRst1 is :

 5

wtfRst2 is :

 19


查看完整回答
反對 回復(fù) 2021-12-09
?
天涯盡頭無女友

TA貢獻(xiàn)1831條經(jīng)驗(yàn) 獲得超9個贊

作為注釋的三重引號字符串必須是有效的 Python 字符串。有效的 Python 字符串必須正確縮進(jìn)。

Python 看到多行字符串,對其進(jìn)行評估,但由于您沒有為其分配變量,因此該字符串在下一行中被丟棄。


查看完整回答
反對 回復(fù) 2021-12-09
?
largeQ

TA貢獻(xiàn)2039條經(jīng)驗(yàn) 獲得超8個贊

您應(yīng)該將三引號字符串的縮進(jìn)級別向右推一個標(biāo)簽。

雖然三引號字符串經(jīng)常被用作注釋,但它們是普通的 Python 表達(dá)式,因此它們應(yīng)該遵循語言的語法。


查看完整回答
反對 回復(fù) 2021-12-09
  • 3 回答
  • 0 關(guān)注
  • 269 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號