Skip to content

Instantly share code, notes, and snippets.

@farynaio
Last active April 22, 2020 19:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save farynaio/ec5ab280f11915cda7c5ecd85281cadd to your computer and use it in GitHub Desktop.
Save farynaio/ec5ab280f11915cda7c5ecd85281cadd to your computer and use it in GitHub Desktop.
Python 3 Build-in And Reserved Keywords

  Boolean related:

  Special values:

  Module asyncio related:

  • async
  • await

  Modules related:

  • import - used to import the content of the module into the current module
  • as - used together with 'import' specifies an alias for imported module
  • from - used together with 'import', it specifies the module to import, and 'import' specifies what functions will be imported

  Functions related:

  • def - define function
  • pass - skip the function definition
  • return - return value from the function
  • lambda - used for creating anonymous, inline functions, without self parameter
  • global - used for declaring a variable inside a function as global (as it was declared outside the function)
  • nonlocal - marks the variable that it refers to the variable defined outside the function, used only when we change the value in nested function (closures)

  Conditional statements related:

  • if - starts a conditional block
  • else - alternative block in a conditional block
  • elif - alternative conditional block with condition check
  • is - returns true if two objects are the same

  Logical operators:

  • and - expression result into True only if both operands are True
  • or - expression result into True only if any of operands is True
  • not - expression result into True only if the operand is False
  • in - used to test if a sequence (string, list, tuple) contains a value

  Loops related:

  • for - starts for loop block
  • while - starts while loop block
  • break - exit execution of the loop
  • continue - skips current loop iteration and go to the next one

  Control flow:

  • with - declares a control-flow structure
  • as - used together with 'with'

  Exceptions related:

  • try - starts try/except block
  • raise - throws an Exception
  • except - starts specific exception handling block
  • finally - starts block executed after the try/except block execution is finished

  Class related:

  • class - used to declare a class
  • pass - used to declare that child class will have the same declaration as it's parent class
  • del - deletes the class

  Variables related:

  • del - deletes the variable or removes value from the sequence (list, tuple, string)

  Generators related:

  • yield - pauses generator execution and returns the value

  Assertion related:

  • assert - declares assertion condition
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment