Keywords
A keyword is an identifier which has some Pre-defined meaning in
python. Keyword cannot be re-defined.
In Python, keywords are reserved words that have special meanings and are used to define the syntax and structure of the language. You cannot use them as variable names, function names, or identifiers.
Below is a clear explanation of Python keywords, grouped by purpose
True / False / None
Keyword Explanation
True Boolean value representing true
False Boolean value representing false
None Represents no value / null value
Logical Operators
Keyword Explanation
and Returns True if both conditions are true
or Returns True if at least one condition is true
not Reverses the logical result
Conditional Statements
Keyword Explanation
if Executes code if condition is true
elif Checks another condition if previous is false
else Executes code if all conditions are false
Looping Keywords
Keyword Explanation
for Loop over a sequence
while Loop while condition is true
break Exit the loop
Function & Class
Keyword Explanation
def Define a function
return Return a value from function
class Define a class
lambda Create a small anonymous function
Exception Handling
Keyword Explanation
try Wrap risky code
except Handle exceptions
finally Execute code no matter what
raise Raise an exception
Import & Modules
Keyword Explanation
import Import a module
from Import specific items
as Create an alias
Scope & Variables
Keyword Explanation
global Declare global variable
nonlocal Refer to outer function variable
Membership & Identity
Keyword Explanation
in Check if value exists
is Check if two objects are same
Asynchronous Programming
Keyword Explanation
async Define asynchronous function
await Wait for async result
Miscellaneous
Keyword Explanation
assert Debugging check
yield Return generator value
del Delete object
Example:
import keyword
print(keyword.kwlist)
The Following Are Python Keywords:
- And
- as
- assert
- break
- class
- continue
- def
- del
- elif
- else
- except
- finally
- for
- from
- if
- import
- global
- in
- is
- not
- or
- pass
- raise
- return
- try
- while
- with
- yield
- false
- none
- true