Saturday, March 21, 2020

Python Keywords

Python Keywords


A reserved keyword is a set of alphabets having some special meaning to the programming language. We can’t use a reserved keyword as the name of a variable, a function, a class, or a module. All the Python keywords contain lowercase letters only. Python also has a set of reserved keyword,

Python keywords
Python keywords

Python Keywords with their description


  • The and keyword is used as a logical operator
  • The as keyword is used to create an alias
  • The assert keyword is used for debugging purpose
  • The break keyword is a break statement
  • The class keyword is used to declare a class
  • The continue keyword is used to continue to the next iteration of a loop
  • The def keyword is used to define a function
  • The del keyword is used to delete an object
  • The elif keyword is used with conditional statements, (same as else if in other languages)
  • The else keyword is used with conditional statements
  • The except keyword is used with exceptions
  • The False is a boolean value, comparison operation either results in True or False
  • The finally keyword is used with exceptions, a block of code that will be executed no matter if there is an exception or not
  • The for keyword is to apply a for loop
  • The from keyword is to import specific parts out of a module
  • The global keyword is to define a global variable
  • The if keyword is to apply a conditional statement
  • The import keyword is used to import a module
  • The in keyword is used to test if a value is available in a list, tuple, etc.
  • The is keyword is used to see if two variables are equal
  • The lambda keyword is used to create an anonymous function
  • The None keyword is used to represents a null value
  • The nonlocal keyword is used to declare a non-local variable
  • The not keyword is used as a logical operator
  • The or keyword is used as a logical operator
  • The pass keyword is a null statement, a pass statement does nothing
  • The raise keyword is used to raise an exception
  • The return keyword is used to exit a function and return a value
  • The True keyword is used as a boolean value like False, comparison operation either results in True or False
  • The try keyword is used to apply the try-except statement
  • The while keyword is used to apply a while loop
  • The with keyword is used with exception handling
  • The yield keyword is used to end a function, yield returns a generator