Keywords in Python
What are the keywords?
Keywords are the unique words reserved with defined meanings and functions that we can only apply for those functions.
You cannot use keywords as a name of any entities like variables, classes and functions.
Almost all keywords in Python are in lowercase except value keywords.
The all keywords in Python are have special meaning associated with them.
There are 33 keywords in Python while creating this tutorial
and | as | assert |
break | class | continue |
def | del | elif |
else | except | flase |
finally | for | from |
global | if | import |
in | is | lambda |
None | nonlocal | not |
or | pass | raise |
return | true | try |
while | with | yield |
Python keywords are distributed as follows:
- Value Keywords: True, False, None.
- Operator Keywords: and, or, not, in, is.
- Control Flow Keywords: if, elif, else.
- Iteration Keywords: for, while, break, continue, else.
- Structure Keywords: def, class, with, as, pass, lambda.
- Returning Keywords: return, yield.
- Import Keywords: import, from, as.
Here is the keywords and their description
Keywords | Description |
---|---|
and | A logical Operator |
as | To create an alias |
assert | For debugging |
break | To break out of a loop |
class | To define a class |
continue | To continue to the net 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 exception, What to do when an exception occurs |
False | Boolean value, result of comparision operation |
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 module |
global | To declare a global variable |
if | To make a conditional statement |
import | To import modules |
in | To check if a value is present in a list, tuple, etc. |
is | To test, if two variables are equal |
lambda | To create anonymous function |
none | Represent 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 |
raise | To raise an exception |
return | To exit a function and return a value |
true | Boolean value, result of comparison operation |
try | To make a try...except block |
while | To create while loop |
with | Used to simplify exception handling |
yield | To end a function, return a generator |
We are going to see use of all the Keywords in next upcoming Toipcs. Let's move forward for next Topic.
0 Comments
Please do not add Any Spam link in Comments !