Python中有幾個關(guān)鍵字
Python中關(guān)鍵詞有多少個?Python中關(guān)鍵詞目前有31個,可以利用Python的內(nèi)置的keyword模塊進(jìn)行輸出查看。
keyword模塊
Help on module keyword:NAME keyword - Keywords (from 'graminit.c')FILE /usr/lib64/python2.6/keyword.pyDESCRIPTION This file is automatically generated; please don’t muck it up! To update the symbols in this file, ’cd’ to the top directory of the python source tree after building the interpreter and run: python Lib/keyword.pyFUNCTIONS iskeyword = __contains__(...) x.__contains__(y) y in x.DATA __all__ = [’iskeyword’, ’kwlist’] kwlist = [’and’, ’as’, ’assert’, ’break’, ’class’, ’continue’, ’def’, ...
得到python的關(guān)鍵字列表:
>>> keyword.kwlist[’and’, ’as’, ’assert’, ’break’, ’class’, ’continue’, ’def’, ’del’, ’elif’, ’else’, ’except’, ’exec’, ’finally’, ’for’, ’from’, ’global’, ’if’, ’import’, ’in’, ’is’, ’lambda’, ’not’, ’or’, ’pass’, ’print’, ’raise’, ’return’, ’try’, ’while’, ’with’, ’yield’]
判斷字符串是否是python的關(guān)鍵字
>>> keyword.iskeyword(’and’)True>>> >>> keyword.iskeyword(’has’)False
關(guān)于關(guān)鍵字知識點(diǎn)擴(kuò)展:
TF-IDF
TF-IDF(Term Frequencey-Inverse Document Frequency)指詞頻-逆文檔頻率,它屬于數(shù)值統(tǒng)計的范疇。使用TF-IDF,我們能夠?qū)W習(xí)一個詞對于數(shù)據(jù)集中的一個文檔的重要性。
TF-IDF的概念
TF-IDF有兩部分,詞頻和逆文檔頻率。首先介紹詞頻,這個詞很直觀,詞頻表示每個詞在文檔或數(shù)據(jù)集中出現(xiàn)的頻率。等式如下:
TF(t)=詞t在一篇文檔中出現(xiàn)的次數(shù)/這篇文檔的總詞數(shù)
第二部分——逆文檔頻率實(shí)際上告訴了我們一個單詞對文檔的重要性。這是因?yàn)楫?dāng)計算TF的時候,我們對每個詞賦予了同等的重要性,它出現(xiàn)得越多,它的TF就越高,如果它出現(xiàn)了100次,也許相比其他出現(xiàn)更少的詞,它并不攜帶那么多信息,因此我們需要賦予它們權(quán)重,決定每個詞的重要性。使用下面的等式得到IDF:
IDF(t)=(log10文檔的篇數(shù)/包含詞t文檔的篇數(shù))
那么,計算TF-IDF的方法如下:
TF * IDF=(詞t在一篇文檔中出現(xiàn)的次數(shù)/這篇文檔的總詞數(shù))* log10(文檔的篇數(shù)/包含詞t文檔的篇數(shù))
到此這篇關(guān)于Python中有幾個關(guān)鍵字的文章就介紹到這了,更多相關(guān)Python中關(guān)鍵字有多少個內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. PHP循環(huán)與分支知識點(diǎn)梳理2. JSP+Servlet實(shí)現(xiàn)文件上傳到服務(wù)器功能3. 利用FastReport傳遞圖片參數(shù)在報表上展示簽名信息的實(shí)現(xiàn)方法4. JavaWeb Servlet中url-pattern的使用5. Ajax請求超時與網(wǎng)絡(luò)異常處理圖文詳解6. jsp實(shí)現(xiàn)textarea中的文字保存換行空格存到數(shù)據(jù)庫的方法7. jsp EL表達(dá)式詳解8. chat.asp聊天程序的編寫方法9. JSP之表單提交get和post的區(qū)別詳解及實(shí)例10. jsp cookie+session實(shí)現(xiàn)簡易自動登錄
