-->

PYTHON KEYWORDS




Python keywords

First, of all we have to know what the keywords term means so, keywords are the reserved words in every programming language that cannot be used as variable names, functions names, class names, or any identifiers. They can only be used to define structure and syntax in every language.

For Example:

keywords in C


auto    break    continue    switch    case    default
 and many more...

Keywords in C++
asm    auto    bool    break    case    catch    char    class
and many more...

Keywords in java

abstract    assert    Boolean    break    if    else    char    int    class
and many more...

Just like that, a question is raised How many keywords in python?


So, the answer is there are 33 keywords in python 3.7  and this number may vary with time.

How to check the list of keywords?


import keyword
print(keyword.kwlist)

OUTPUT


['False', 'None', 'True', '__peg_parser__', 'and', 'as', 'assert', 'async', 'await', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']

After analyzing the python keyword list everyone can say that except True, False and None every keyword is in lowercase

These are the short description of all keywords: -


keywordDescription
andA logical operator
asTo create an alias
assetFor debugging
breakTo break out of a loop
class To define a class
continueTo continue to the next iteration of a loop
defTo define a function
delTo delete an object
elifUsed in conditional statements, same as else if
elseUsed in conditional statements
exceptUsed with exceptions, what to do when an exception occurs
FalseBoolean value, result of comparison operations
finallyUsed with exceptions, a block of code that will be executed no matter if there is an exception or not
forTo create a for loop
fromTo import specific parts of a module
globalTo declare a global variable
ifTo make a conditional statement
importTo import a module
in To check if a value is present in a list, tuple, etc.
isTo test if two variables are equal
lambdaTo create an anonymous function
noneRepresents a null value
nonlocalTo declare a non-local variable
notA logical operator
orA logical operator
passA null statement, a statement that will do nothing

Read Also

Post a Comment