keywords
keywords
 Keywords in Python are reserved words that have special meaning and
purpose in the language.
 You cannot use them as variable names function names, or identifiers .
 Why are keywords important?
 They help Python understand the structure and logic of your code .
Rules About Keywords:
 Cannot be used as variable/function names.
 Are case-sensitive
 Fixed and predefined — can't be modified.
 False await else import pass
 None break except in raise
 True class finally is return
 and continue for lambda try
 as def from nonlocal while
 assert del global not with
 async elif if or yield
Basic Logic and Control Flow Keywords
Keyword Purpose / Use
False
Boolean value representing false
condition
True
Boolean value representing true
condition
None Represents a null or no value
and Logical AND operator
or Logical OR operator
not Logical NOT operator
if Begins a conditional block
elif Else-if block in conditions
else Executes if all if/elif conditions fail
for Starts a loop over an iterable
while Repeats a block while condition is true
break Exits a loop early
Function, Class, Exception, and Scope
Keywords
Keyword Purpose / Use
continue Skips to the next iteration of a loop
pass
A no-op (does nothing); used as a
placeholder
def Defines a function
return Sends a value back from a function
lambda Creates an anonymous function
yield
Used in generator functions to return
values one by one
import Imports a module
from Imports specific part of a module
as
Gives a name/alias to module or
exception
class Defines a class
try Starts a try block for error handling
except Catches and handles exceptions
Advanced, Async, and Miscellaneous
Keywords
Keyword Purpose / Use
finally Block that always executes after try/except
raise Raises an exception manually
assert Used for debugging; raises error if condition is false
with Context manager (e.g., file handling)
del Deletes variables or list elements
global Declares a global variable in a function
nonlocal Refers to a variable in outer (non-global) scope
is
Tests identity (whether two references point to the same
object)
in Checks if value is in a container
async Declares a coroutine (asynchronous function)
await Awaits result from an async function
None (Repeated for completeness: represents no value)
 # Check if a number is positive or negative
 num = -3
 if num >= 0:
 print("Positive number")
 else:
 print("Negative number")
if, else, print
 # Print numbers until we find 5
 for i in range(10):
 if i == 5:
 break
 print(i)
for, in, break
 # Function to add two numbers
 def add(x, y):
 return x + y
 print("Sum:", add(4, 6))
def, return, print
 # Skip even numbers using continue
 i = 0
 while i < 5:
 i += 1
 if i % 2 == 0:
 continue
 print(i)
while, continue, print
 # Handle division by zero
 try:
 result = 10 / 0
 except ZeroDivisionError:
 print("Cannot divide by zero!")
try, except, print

kewords in python using 35 keywords.pptx

  • 1.
  • 2.
    keywords  Keywords inPython are reserved words that have special meaning and purpose in the language.  You cannot use them as variable names function names, or identifiers .  Why are keywords important?  They help Python understand the structure and logic of your code .
  • 3.
    Rules About Keywords: Cannot be used as variable/function names.  Are case-sensitive  Fixed and predefined — can't be modified.
  • 4.
     False awaitelse import pass  None break except in raise  True class finally is return  and continue for lambda try  as def from nonlocal while  assert del global not with  async elif if or yield
  • 5.
    Basic Logic andControl Flow Keywords Keyword Purpose / Use False Boolean value representing false condition True Boolean value representing true condition None Represents a null or no value and Logical AND operator or Logical OR operator not Logical NOT operator if Begins a conditional block elif Else-if block in conditions else Executes if all if/elif conditions fail for Starts a loop over an iterable while Repeats a block while condition is true break Exits a loop early
  • 6.
    Function, Class, Exception,and Scope Keywords Keyword Purpose / Use continue Skips to the next iteration of a loop pass A no-op (does nothing); used as a placeholder def Defines a function return Sends a value back from a function lambda Creates an anonymous function yield Used in generator functions to return values one by one import Imports a module from Imports specific part of a module as Gives a name/alias to module or exception class Defines a class try Starts a try block for error handling except Catches and handles exceptions
  • 7.
    Advanced, Async, andMiscellaneous Keywords Keyword Purpose / Use finally Block that always executes after try/except raise Raises an exception manually assert Used for debugging; raises error if condition is false with Context manager (e.g., file handling) del Deletes variables or list elements global Declares a global variable in a function nonlocal Refers to a variable in outer (non-global) scope is Tests identity (whether two references point to the same object) in Checks if value is in a container async Declares a coroutine (asynchronous function) await Awaits result from an async function None (Repeated for completeness: represents no value)
  • 8.
     # Checkif a number is positive or negative  num = -3  if num >= 0:  print("Positive number")  else:  print("Negative number") if, else, print
  • 9.
     # Printnumbers until we find 5  for i in range(10):  if i == 5:  break  print(i) for, in, break
  • 10.
     # Functionto add two numbers  def add(x, y):  return x + y  print("Sum:", add(4, 6)) def, return, print
  • 11.
     # Skipeven numbers using continue  i = 0  while i < 5:  i += 1  if i % 2 == 0:  continue  print(i) while, continue, print
  • 12.
     # Handledivision by zero  try:  result = 10 / 0  except ZeroDivisionError:  print("Cannot divide by zero!") try, except, print