Skip to main content

Comments

Utilizing comments throughout your code not only help keep your thoughts together but they also help the next developer understand what you are doing.  Their use should be quick and to the point but descriptive enough to be understood by someone who has never seen your code.  The two primary methods to document your work is shown below.

 

# This is an inline comment defined by the hash symbol to its left

someVar = 0  # It can be used to the right of the code like this

def someFunction():
  # Or within a function
  pass

# Or across
# Multiple lines
# Like this

# Don't use it before your code because 
# the interpreter will ignore the etire line someVar = 0

Doc Strings are defined as below.  They help define what a specific function or method is and how its used.  These are used in most code completion environments and in VS Code, Doc Strings are used in pop ups which show the user how to call the function or method so the format should be adhered to.

# Below is a couple examples of a doc string
# Doc Strings start and end with three double quotes.
# The last set of three double quotes are on the same line
# only if the Doc String is all on one line.

# The first one is used only if the function is obvious an no explanation is needed

# The second one is used if more information is needed to properly explain what it does

def addNumbers(num1, num2):
  """Add two numbers"""
  return num1 + num2

def complex(real=0.0, imag=0.0):
  """Form a complex number.
  
  Keyword arguments:
  real -- the real part (default 0.0)
  imag -- the imaginary part (default 0.0)
  """
  if imag == 0.0 and real == 0.0:
    return complex_zero