Keywords in Python are reserved words that hold special predefined meanings and form the foundation of the language’s syntax. They cannot be used as identifiers, including variable names, function names, or any other custom labels. There are 35 keywords.
Table of Contents
Table of Python Keywords
Keyword | Description | Example |
TRUE | Represents the Boolean value true. | c = True |
FALSE | Represents the Boolean value false. | a = False |
None | Represents a null value or “nothing.” | b = None |
and | Logical AND operator. | if x > 0 and x < 10: |
or | Logical OR operator. | if x > 0 or y > 0: |
not | Logical NOT operator. | if not x: |
is | Tests object identity. | if x is None: |
in | Check if a value exists within a collection. | if ‘a’ in my_list: |
if | Starts a conditional statement. | if x > 10: |
elif | Else if condition in an if statement. | if x > 10: elif x > 5: |
else | Executes a block of code if the if condition is false. | if x > 10: else: |
for | Creates a for loop. | for i in range(10): |
while | Creates a while loop. | while x < 10: |
break | Terminates the nearest enclosing loop. | for i in range(10): if i == 5: break |
continue | Skips the rest of the loop iteration. | for i in range(10): if i % 2 == 0: continue |
pass | A null statement, a placeholder. | def empty_function(): pass |
def | Used to define a function or method. | def my_function(): |
return | Exits a function and returns a value. | return x + y |
lambda | Creates an anonymous function. | lambda x: x + 1 |
nonlocal | Declares a non-local variable. | nonlocal x |
global | Declares a global variable. | global x |
await | Pauses execution of async functions. | await fetch_data() |
import | Used to import modules. | import math |
from | Imports specific parts of a module. | from math import pi |
as | Used to create an alias. Commonly used in import statements. | import math as m |
class | Used to define a class. | class MyClass: |
try | Specifies exception handling. | try: raise ValueError |
except | Catches exceptions in try/except blocks. | try: except ValueError: |
finally | Executes code regardless of exceptions. | try: finally: |
raise | Raises an exception. | raise ValueError |
assert | For debugging purposes, to test if a condition is true. | assert x == 10 |
del | Deletes objects. | del my_variable |
async | Declares an asynchronous function. | async def fetch_data() |
with | Wraps the execution of a block of code. | with open(‘file.txt’) as f: |
yield | Used in generators to return a value. | yield x |
Note: will understand each and everything in upcoming individual topics.
Key Points to Remember
- Immutable: Keywords are case-sensitive and must be written in lowercase.
- Reserved: They cannot be used as identifiers like variable names, function names, or class names.
- Evolving Language: New keywords may be added in future Python versions.
- Special Purposes: Each keyword serves a specific role in controlling the flow, structure, and behavior of the code.
Conclusion
Keywords are important to Python’s syntax and are used to define the language’s structure and logic. Keywords are essential for writing effective and clear Python code.
Knowledge Check
Related Article No.3
Check out our Trending Courses Demo Playlist
Data Analytics with Power Bi and Fabric |
Could Data Engineer |
Data Analytics With Power Bi Fabic |
AWS Data Engineering with Snowflake |
Azure Data Engineering |
Azure & Fabric for Power bi |
Full Stack Power Bi |
Kick Start Your Career With Our Data Job
Social Media channels
► KSR Datavizon Website :- https://www.datavizon.com
► KSR Datavizon LinkedIn :- https://www.linkedin.com/company/datavizon/
► KSR Datavizon You tube :- https://www.youtube.com/c/KSRDatavizon
► KSR Datavizon Twitter :- https://twitter.com/ksrdatavizon
► KSR Datavizon Instagram :- https://www.instagram.com/ksr_datavision
► KSR Datavizon Face book :- https://www.facebook.com/KSRConsultingServices
► KSR Datavizon Playstore :- https://play.google.com/store/apps/details?id=com.datavizon.courses&hl=en-IN
► KSR Datavizon Appstore :- https://apps.apple.com/in/app/ksr-datavizon/id1611034268
Most Commented