Basic Keywords in Python Language

As a programmer, you all know that python language is a programming language, there are basic keywords in Python that every programmer must know all what is all about, the basic keywords are: pass, return, while, True and False, None, (and, or, not), with, yield, for, from and import, as, assert, break and continue, class, def, del, global, in, is, (if, else, elif), (except, raise, try) and finally.

Below are notes on each of the Keywords:

  • Pass:- is a null statement in Python, Nothing happens when it is executed. It is used as a placeholder.
  • Return:- statement is used inside a function to exit it and return a value.
  • While:- While is used for looping in Python.
  • True and False:- are truth values in Python. They are the results of comparison operations or logical (Boolean) operations in Python.
  • None:- None is a special constant in Python that represents the absence of a value or a null value.
  • And, or, not:- are the logical operations in Python.
  • With:- statement is used to wrap the execution of a block of code within methods defined by the context manager.  
  • Yield:- is used to wrap the execution of a block of code within methods defined by the context manager.e 
  • For:- is used for looping. Generally we use for when we know the number of times we want to loop.
  • From and import:- import keyword is used to import modules into the current namespaces. from---import is used to import specific attributes or functions into the current namespace.
  • As:- is used to create an alias while importing a module. It means giving a different name (user-defined) to a module while importing it.
  • Assert:- is used for debugging purposes.
  • Break and Continue:- are used inside for and while loops to alter their normal behaviour.
  • Class:- is used to define a new user-defined class in Python.
  • Def:- is used to define a user-defined function.
  • Del:- is used to delete the reference to an object.
  • Global:- is used to declare that a variable inside the function is global.
  • In:- is used to test if a sequence (list, tuple, string etc.)contains a value.
  • Is:- is used in Python for testing object identify
  • If, else, elif:- are used for conditional branching or decision making.
  • Except, raise and try:- are used with exceptions in Python.
  • Finally:- is used with try---except block to close up resources or file streams.
Below are more images to backup the notes:









Post a Comment

0 Comments