python keywords

Keywords.jpg

What is Reserved Keywords?

Keywords are reserved words in a programming language that have predefined meanings and are used to perform specific tasks. In Python, keywords play a crucial role in defining the syntax and structure of the code. They are fundamental building blocks that help programmers write meaningful and functional programs.

Python keywords cannot be used as identifiers (variable names, function names, etc.) because they are already designated for specific purposes within the language. This ensures clarity and consistency in code interpretation by both humans and the Python interpreter.

Python offers a comprehensive set of keywords that cover various programming aspects, including control flow, data manipulation, defining functions and classes, handling exceptions, and more.

List of Reserved Keywords

False

None

True

and

as

assert

async

await

break

class

continue

def

del

elif

else

except

finally

for

from

global

if

import

in

is

lambda

nonlocal

not

or

pass

raise

return

try

while

with

yield

  1. False: A boolean value representing false.
  2. None: Represents the absence of a value or a null value.
  3. True: A boolean value representing true.
  4. and: A logical operator used to combine conditions. Returns true if both conditions are true.
  5. as: Used to create an alias when importing modules or using "with" statements.
  6. assert: A debugging aid that tests a condition as true. If it's false, an exception is raised.
  7. async: Declares a coroutine, allowing asynchronous programming.
  8. await: Pauses the execution of a coroutine until an awaited event completes.
  9. break: Terminates the current loop (for or while) and resumes execution after the loop.
  10. class: Defines a class, which is a blueprint for creating objects with specific properties and methods.
  11. continue: Skips the rest of the current iteration of a loop and starts the next iteration.
  12. def: Defines a function, a reusable block of code that performs a specific task.
  13. del: Deletes a variable, list item, dictionary key, or attribute from an object.
  14. elif: Stands for "else if." Used with if statements to add additional conditions.
  15. else: Part of if statements, executed if the condition(s) in the if or elif statements are false.
  16. except: Part of try-except blocks, catches and handles exceptions.
  17. finally: Part of try-except blocks, specifies code that should be executed regardless of whether an exception occurs.
  18. for: Initiates a loop that iterates over a sequence, such as a list, tuple, or string.
  19. from: Used to import specific attributes or functions from a modules.
  20. global: Declares a variable as global, allowing it to be accessed from within functions.
  21. if: Begins an if statement, used for conditional execution of code.
  22. import: Imports a module, allowing you to use its functions and attributes in your code.
  23. in: Used to test if a value is present in a sequence (like a list, tuple, or string).
  24. is: Tests if two variables refer to the same object in memory.
  25. lambda: Creates an anonymous function (a function with no name) using a lambda expression.
  26. nonlocal: Used within a nested function to indicate that a variable is in an outer (but non-global) scope.
  27. not: A logical operator that negates the truth value of an expression.
  28. or: A logical operator that returns true if at least one of the conditions is true.
  29. pass: A placeholder statement that does nothing. Used when a statement is syntactically required but no action is needed.
  30. raise: Raises an exception manually.
  31. return: Used in a function to exit the function and optionally return a value.
  32. try: Begins a try-except block, used for exception handling.
  33. while: Initiates a loop that continues as long as the given condition is true.
  34. with: Creates a context manager for resources that should be acquired and released automatically.
  35. yield: Used in a generator function to pause execution and produce a value for the caller.

Read More : https://www.codinguru.online/python/python-identifiers