Python for Finance: Analyze Big Financial Data

(Elle) #1

for i in range( 3 , end, 2 ):
if I % i == 0 :
print “Number is not prime, it is divided by %d.” % i
break
if i >= end - 2 :
print “Number is prime.”


In general, such a documentation string provides information about the following


elements:


Input


Which parameters/arguments to provide, and in which format (e.g., int)


Output


What the function/method returns, and in which format


Errors


Which (“special”) errors might be raised


Examples


Example usage of the function/methods


The use of documentation strings is not only helpful for those who take a look at the code


itself. The majority of Python tools, like IPython and Spyder, allow direct access to this


documentation and help source. Figure A-1 shows a screenshot of Spyder, this time with


the function is_prime shown in the editor and the rendered documentation string of the


function in the object inspector (upper right). This illustrates how helpful it is to always


include meaningful documentation strings in functions and classes.

Free download pdf