如何查看python關(guān)鍵字
現(xiàn)在我們就來講講關(guān)鍵字吧,準備好開始記筆記了吧,俗話說得好,好記性不如爛筆頭,記好了喔,經(jīng)常聽大家提起關(guān)于Python中關(guān)鍵詞有多少個?實際上Python中關(guān)鍵詞目前有31個,想要具體查看以及觀察個數(shù)的方式非常簡單,下面就為大家詳細介紹。
1、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’, ...
2、得到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’]
3、判斷字符串是否含關(guān)鍵字
>>> keyword.iskeyword(’and’)True>>> >>> keyword.iskeyword(’has’)False
Python關(guān)鍵字知識點擴展:
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ù)
第二部分——逆文檔頻率實際上告訴了我們一個單詞對文檔的重要性。這是因為當計算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)文章:
