Here we provide, technology updates, sports updates, defense updates and educational blogs, HISTORY, Linux Tutorials, Python Tutorial
- Home
- About us
- Contact us
- Sitemap
- Disclaimer
- Privacy Policy
- Terms and Condition
-
Settings
- Dark mode
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
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: -
keyword | Description |
---|---|
and | A logical operator |
as | To create an alias |
asset | For debugging |
break | To break out of a loop |
class | To define a class |
continue | To continue to the next iteration of a loop |
def | To define a function |
del | To delete an object |
elif | Used in conditional statements, same as else if |
else | Used in conditional statements |
except | Used with exceptions, what to do when an exception occurs |
False | Boolean value, result of comparison operations |
finally | Used with exceptions, a block of code that will be executed no matter if there is an exception or not |
for | To create a for loop |
from | To import specific parts of a module |
global | To declare a global variable |
if | To make a conditional statement |
import | To import a module |
in | To check if a value is present in a list, tuple, etc. |
is | To test if two variables are equal |
lambda | To create an anonymous function |
none | Represents a null value |
nonlocal | To declare a non-local variable |
not | A logical operator |
or | A logical operator |
pass | A null statement, a statement that will do nothing |
Post a Comment
Post a Comment
if you have any doubts, please let me know