Skip to content

Python Keywords | Infographic

  • by

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:

KeywordDefinition
FalseBoolean value representing false
NoneRepresents the absence of a value
TrueBoolean value representing true
andLogical AND operator
asAlias for a module or class name
assertUsed for debugging purposes to check a condition
asyncDeclares an asynchronous function or context manager
awaitPauses execution until the result is ready in async function
breakExits from the innermost loop
classDefines a class
continueSkips the rest of the code inside a loop and continues with the next iteration
defDefines a function
delDeletes a variable or item in a list or dictionary
elifUsed in conditional statements as “else if”
elseUsed in conditional statements for the alternative case
exceptCatches exceptions during exception handling
FalseBoolean value representing false
finallyExecutes code, regardless of whether an exception occurred or not
forIterates over a sequence (e.g., list, tuple, string)
fromUsed in import statements to specify the module to import from
globalDeclares a variable as global in scope
ifConditional statement, executes code if a condition is true
importImports a module or specific items from a module
inMembership test (used to test if a value exists in a sequence)
isCompares object identity
lambdaCreates an anonymous function (a.k.a. lambda function)
nonlocalDeclares a variable as nonlocal in scope
notLogical NOT operator
orLogical OR operator
passPlaceholder that does nothing (used as a syntactic filler)
raiseRaises an exception
returnReturns a value from a function
TrueBoolean value representing true
tryStarts a block of code that might raise an exception
whileCreates a loop that continues as long as a condition is true
withSimplifies resource management using a context manager
yieldPauses 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.

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading