Python Cheat Sheet

Statements

  • if condition:
  • for item in collection:
  • while condition:

Types

  • integer
  • string
  • float
  • boolean

Math

  • + : plus
  • : minus
  • * : times
  • / : divide
  • % : remainder

Conditions

  • == : equals
  • != : does not equal
  • > : is greater than
  • < : is less than
  • >= : is greater than or equal to
  • <= : is less than or equal to

Functions

  • def function_name(parameters):
    return something
  • input(question)
  • len(collection)
  • print(anything)
  • range(number)
  • sum(numbers)
  • math.factorial(number)
  • math.sqrt(number)
  • random.randint(from, to)
  • random.randrange(number)