All Keywords in Python language.
as
as is used to create an alias while importing a module. It means giving a different name (user-defined) to a module while importing it.
assert
assert is used for debugging purposes
break and continue
break and continue are used inside for and while loops to alter their normal behavior
True and False
True and False are truth values in Python. They are the results of comparison operations or logical (Boolean) operations in Python.
None
None is a special constant in Python that represents the absence of a value or a null value
and, or, not
and, or, not are the logical operators in Python
class
class is used to define a new user-defined class in Python
def
def is used to define a user-defined function
del
del is used to delete the reference to an object
if, else, elif
if, else, elif are used for conditional branching or decision-making
except, raise, try
except, raise, and try are used with exceptions in Python
finally
finally is used with block to close up resources or file streams
global
global is used to declare that a variable ‘inside the function is global
in
in is used to test if a sequence (list, tuple, string, etc.)
contains a value
is
is used in Python for testing object identity
pass
pass is a null statement in Python. Nothing happens when it is executed. It is used as a placeholder
return
return statement is used inside a function to exit it and return a value
while
while is used for looping in Python
for
for is used for looping. Generally, we use it when we know the number of times we want to loop.
from and import
import keyword is used to import modules into the current namespace. is used to import specific attributes or functions into the current namespace
with
with statement is used to wrap the execution of a block of code within methods defined by the context manager
yield
yield is used inside a function like a return statement. But yield returns a generator
Here’s a table with Python keywords along with brief definitions:
Keyword | Definition |
---|---|
False | Boolean value representing false |
None | Represents the absence of a value |
True | Boolean value representing true |
and | Logical AND operator |
as | Alias for a module or class name |
assert | Used for debugging purposes to check a condition |
async | Declares an asynchronous function or context manager |
await | Pauses execution until the result is ready in async function |
break | Exits from the innermost loop |
class | Defines a class |
continue | Skips the rest of the code inside a loop and continues with the next iteration |
def | Defines a function |
del | Deletes a variable or item in a list or dictionary |
elif | Used in conditional statements as “else if” |
else | Used in conditional statements for the alternative case |
except | Catches exceptions during exception handling |
False | Boolean value representing false |
finally | Executes code, regardless of whether an exception occurred or not |
for | Iterates over a sequence (e.g., list, tuple, string) |
from | Used in import statements to specify the module to import from |
global | Declares a variable as global in scope |
if | Conditional statement, executes code if a condition is true |
import | Imports a module or specific items from a module |
in | Membership test (used to test if a value exists in a sequence) |
is | Compares object identity |
lambda | Creates an anonymous function (a.k.a. lambda function) |
nonlocal | Declares a variable as nonlocal in scope |
not | Logical NOT operator |
or | Logical OR operator |
pass | Placeholder that does nothing (used as a syntactic filler) |
raise | Raises an exception |
return | Returns a value from a function |
True | Boolean value representing true |
try | Starts a block of code that might raise an exception |
while | Creates a loop that continues as long as a condition is true |
with | Simplifies resource management using a context manager |
yield | Pauses execution and returns a value from a generator function |
Note: This table provides brief definitions, and for a more detailed understanding, you may refer to the Python documentation or tutorials.