KEYWORDS IN PYTHON

KEYWORDS IN PYTHON

Gocourse

    


Keywords

A  keyword is an identifier which has some Pre-defined meaning in python. Keyword cannot be re-defined.

In Python, keywords are reserved words that have special meanings and are used to define the syntax and structure of the language. You cannot use them as variable names, function names, or identifiers.

Below is a clear explanation of Python keywords, grouped by purpose 

True / False / None
Keyword Explanation
True Boolean value representing true
False Boolean value representing false
None Represents no value / null value

Logical Operators
Keyword Explanation
and    Returns True if both conditions are true
or         Returns True if at least one condition is true
not         Reverses the logical result

Conditional Statements
Keyword Explanation
if        Executes code if condition is true
elif         Checks another condition if previous is false
else   Executes code if all conditions are false

Looping Keywords
Keyword Explanation
for         Loop over a sequence
while Loop while condition is true
break Exit the loop

Function & Class
Keyword Explanation
def         Define a function
return Return a value from function
class Define a class
lambda Create a small anonymous function

Exception Handling
Keyword Explanation
try    Wrap risky code
except Handle exceptions
finally Execute code no matter what
raise Raise an exception

Import & Modules
Keyword Explanation
import Import a module
from Import specific items
as     Create an alias

Scope & Variables
Keyword Explanation
global Declare global variable
nonlocal Refer to outer function variable

Membership & Identity
Keyword Explanation
in         Check if value exists
is         Check if two objects are same

Asynchronous Programming
Keyword Explanation
async Define asynchronous function
await Wait for async result

Miscellaneous
Keyword Explanation
assert Debugging check
yield Return generator value
del    Delete object

Example:

import keyword
print(keyword.kwlist)

The Following Are Python Keywords:

  1. And
  2. as
  3. assert
  4. break
  5. class
  6. continue
  7. def
  8. del
  9. elif
  10. else
  11. except
  12. finally
  13. for
  14. from
  15. if
  16. import
  17. global
  18. in
  19. is
  20. not
  21. or
  22. pass
  23. raise
  24. return
  25. try
  26. while
  27. with
  28. yield
  29. false
  30. none
  31. true



More topic in Python

Our website uses cookies to enhance your experience. Learn More
Accept !