Python Keywords

In Python, keywords are reserved words that have a special meaning in the language. They are used to perform specific operations or to define the structure of the program. There are 35 keywords in Python, and they cannot be used as variable names, function names, or any other identifier names.

Here is a list of some of the most commonly used keywords in Python:

  • and: used to combine two or more conditions in a logical expression
  • as: used to import a module using an alias
  • assert: used to check if a certain condition is true, and raises an exception if it is not
  • async: used to define an asynchronous function
  • await: used to wait for an asynchronous function to complete
  • break: used to exit a loop
  • class: used to define a new class
  • continue: used to skip the current iteration of a loop
  • def: used to define a new function
  • del: used to delete an object or an element from a collection
  • elif: used as a short form for "else if" in a conditional statement
  • else: used as a part of a conditional statement
  • except: used to handle exceptions
  • False: a boolean literal representing the value False
  • finally: used to specify a block of code that will be executed regardless of whether an exception is raised
  • for: used to create a for loop
  • from: used to import specific elements from a module
  • global: used to specify that a variable is a global variable
  • if: used as a part of a conditional statement
  • import: used to import a module
  • in: used to check if an element is present in a sequence
  • is: used to check if two variables refer to the same object
  • lambda: used to create an anonymous function
  • None: a special constant representing the absence of a value
  • nonlocal: used to specify that a variable is nonlocal
  • not: used to negate a logical expression
  • or: used to combine two or more conditions in a logical expression
  • pass: used as a placeholder when a statement is required but no action is to be performed
  • raise: used to raise an exception
  • return: used to exit a function and return a value
  • True: a boolean literal representing the value True
  • try: used to enclose a block of code that may raise an exception
  • while: used to create a while loop
  • with: used to create a context manager
  • yield: used to define a generator function

Note that all keywords except for True, False, and None are in lowercase and must be written as they are.

It is important to note that keywords cannot be used as variable names, function names or any other identifier.