Python - Things to know before proceed - Keyword Tutorial
Python keywords are special keywords that cannot be used as a variable name or another identifier.
Following are the list of Python keywords:
Sr. No |
Keyword |
Description |
|
true |
It is Boolean value. If the condition is true, then it will return ‘True’. |
|
false |
It is a Boolean value. If the condition is false, then it will return ‘False’. |
|
and |
It is a logical Operator. It is used to check multiple conditions. If any one condition is false, then it will return ‘False’. Otherwise, it will return ‘True’. |
|
or |
It is a logical Operator. It is used to check multiple conditions. If any one condition is true, then it will return ‘True’. Otherwise, it will return ‘False’. |
|
not |
It is a logical Operator. It will invert the Boolean value. If it is true, then it will invert it to ‘False’. If it is false, then it will invert it to ‘True’. |
|
if |
It is used to check conditions. If the condition is true it will execute the block, otherwise, it will skip the block. |
|
else |
Else condition is used with if condition. Else block will be executed only when, if the condition is false. |
|
Elif |
It is the same as else if condition. Elif condition can be used between if and else, multiple times. It will check until the true condition is found. |
|
break |
It is used to terminate the loop iteration and jump out to the end of the loop. |
|
continue |
It is used to skip the execution of the current iteration and then continue until its ends. |
|
none |
The none keyword is used as a null value. The none keyword does not represent 0, null or empty. |
|
as |
‘as’ is used as an alias. It is been used to give a short name or user-defined name while importing a module. |
|
assert |
The assert keyword is used as debugging tool. It will raise an AssertionError if the condition returns false and print the error message. |
|
def |
def keyword is used to define function. It is followed by the function name. |
|
try |
Try keyword is used to handle the exception. If there is an error in a try block, you can define different blocks for different error types. |
|
except |
Except keyword is used to handle the exception. It will define a block of code to run if a try block raises an error. |
|
for |
For loop is used for iteration through a sequence like a list, tuples, dictionary, and string. |
|
while |
While loop is used for iteration until the statement is false |
|
from |
From keyword is used to import only a specific function or attributes from the module. |
|
global |
Global keywords make the variable that can be accessed anywhere in the program. |
|
import |
Import keyword is used to import module for a python project. |
|
in |
|
|
is |
Is keyword is used to test if two variables referring to the same object or not? It will true on same, otherwise false |
|
lambda |
Lambda keyword is used as an inline function with any no. of argument and a single expression. |
|
nonlocal |
The nonlocal keyword is used with a variable in the nested loop to show that the Nonlocal variable does not belong to the inner function |
|
pass |
Pass keyword is used to avoid getting an error, whenever the code is empty |
|
raise |
Raise keyword is used with an exception to define what type of error to be raised. |
|
return |
The return keyword is used to return the result value when the code is exited |
|
finally |
Finally keyword is used to create a block that will always execute, no matter if they try block raises an error or not |
|
with |
With keyword is used in the exception handling. It makes the code more readable. |
|
yield |
Yield keyword will end the function and return a generator to the caller |