Monday, 19 September 2016

Python: Specifications (docstring)

In writing Python codes, creator of the code/program is encourage to add a few lines of comments, also called docstrings, that describe what the code does, the input and the output.

Assumption: expected input from the user
Guarantees: here's what the function will do, given the proper input


def is_even(i):
 """
 Input: i, positive int
 Returns True if i is even, otherwise False
 """
      return i%2==0
          
is_even(3)

No comments:

Post a Comment