There are several keywords in Python

How many keywords are there in Python? There are currently 31 keywords in Python, which can be output and viewed using Python's built-in keyword module.

keyword module

Help on module keyword:
NAME
 keyword -Keywords(from"graminit.c")
FILE
 /usr/lib64/python2.6/keyword.py
DESCRIPTION
 This file is automatically generated; please don't muck it up!
 To update the symbols inthis file,'cd' to the top directory of
 the python source tree after building the interpreter and run:
 python Lib/keyword.py
FUNCTIONS
 iskeyword =__contains__(...)
 x.__contains__(y) y in x.
DATA
 __ all__ =['iskeyword','kwlist']
 kwlist =['and','as','assert','break','class','continue','def',...

Get a list of python keywords:

 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']

Determine whether the string is a keyword of python

 keyword.iskeyword('and')
True
    
 keyword.iskeyword('has')
False

About keyword knowledge point expansion:

TF-IDF

TF-IDF (Term Frequencey-Inverse Document Frequency) refers to term frequency-inverse document frequency, which belongs to the category of numerical statistics. Using TF-IDF, we can learn the importance of a word to a document in the data set.

The concept of TF-IDF

TF-IDF has two parts, term frequency and inverse document frequency. First introduce the word frequency. This word is very intuitive. The word frequency indicates the frequency of each word in the document or data set. The equation is as follows:

TF(t)=The number of times the word t appears in a document / the total number of words in this document

The second part-the inverse document frequency actually tells us the importance of a word to the document. This is because when calculating TF, we assign equal importance to each word. The more it appears, the higher its TF. If it appears 100 times, it may appear less words than other words. , It does not carry so much information, so we need to give them weight to determine the importance of each word. Use the following equation to get IDF:

IDF(t)=(number of log10 documents/number of documents containing word t)

Then, the method of calculating TF-IDF is as follows:

TF * IDF= (the number of times the word t appears in a document / the total number of words in this document) * log10 (the number of documents / the number of documents containing the word t)

So far, this article about a few keywords in Python has been introduced. For more related keywords in Python, please search for the previous articles of ZaLou.Cn or continue to browse the related articles below. Hope you will have more in the future. Support ZaLou.Cn!

Recommended Posts

There are several keywords in Python
There are several versions of python
Is there function overloading in python
Is there an algorithm in python language
What are web development frameworks in python
Is there a helper function in python
Functions in python
03. Operators in Python entry
What conditions are needed for infinite loop in Python
Join function in Python
print statement in python
Concurrent requests in Python
Install python in Ubuntu
Context management in Python
Arithmetic operators in python
Python data visualization: who are the big names in Python?
Write gui in python
MongoDB usage in Python
Str string in Python
Computational Geometry in Python
What are the ways to open files in python
Concurrent requests in Python (part 2)
What are python class attributes
Subscripts of tuples in Python
Talking about inheritance in Python
Noteworthy update points in Python 3.9
Containerize Python applications in 3 minutes
What is introspection in python
What is object-oriented in python
Generators and iterators in Python
Talking about strings in Python