Python中有幾個關鍵字
Python中關鍵詞有多少個?Python中關鍵詞目前有31個,可以利用Python的內置的keyword模塊進行輸出查看。
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的關鍵字列表:
>>> 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的關鍵字
>>> keyword.iskeyword(’and’)True>>> >>> keyword.iskeyword(’has’)False
關于關鍵字知識點擴展:
TF-IDF
TF-IDF(Term Frequencey-Inverse Document Frequency)指詞頻-逆文檔頻率,它屬于數(shù)值統(tǒng)計的范疇。使用TF-IDF,我們能夠學習一個詞對于數(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)更少的詞,它并不攜帶那么多信息,因此我們需要賦予它們權重,決定每個詞的重要性。使用下面的等式得到IDF:
IDF(t)=(log10文檔的篇數(shù)/包含詞t文檔的篇數(shù))
那么,計算TF-IDF的方法如下:
TF * IDF=(詞t在一篇文檔中出現(xiàn)的次數(shù)/這篇文檔的總詞數(shù))* log10(文檔的篇數(shù)/包含詞t文檔的篇數(shù))
到此這篇關于Python中有幾個關鍵字的文章就介紹到這了,更多相關Python中關鍵字有多少個內容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持好吧啦網(wǎng)!
相關文章:
1. 學python最電腦配置有要求么2. Spring security 自定義過濾器實現(xiàn)Json參數(shù)傳遞并兼容表單參數(shù)(實例代碼)3. JAMon(Java Application Monitor)備忘記4. Java8內存模型PermGen Metaspace實例解析5. python中用Scrapy實現(xiàn)定時爬蟲的實例講解6. 基于python實現(xiàn)操作git過程代碼解析7. python使用QQ郵箱實現(xiàn)自動發(fā)送郵件8. Python Scrapy多頁數(shù)據(jù)爬取實現(xiàn)過程解析9. 解決redis與Python交互取出來的是bytes類型的問題10. Python 的 __str__ 和 __repr__ 方法對比
