Book Image

Python for Finance

By : Yuxing Yan
Book Image

Python for Finance

By: Yuxing Yan

Overview of this book

Table of Contents (20 chapters)
Python for Finance
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Using dir() to find variables and functions


After assigning values to a few variables, we could use the dir() function to show their existence. In the following example, variables n, pv, and r are shown among other names. At the moment, just ignore the first five objects in the following code, which start and end with two underscores:

>>>pv=100
>>>r=0.1
>>>n=5
>>>dir()
['__builtins__', '__doc__', '__loader__', '__name__', '__package__', 'n', 'pv', 'r']

Deleting or unsigning a variable

Sometimes, when we write our programs, it might be a good idea to delete those variables that we no longer need. In this case, we could use the del() function to remove or unsign a variable. In the following example, we assign a value to rate, show its value, delete it, and type the variable name trying to retrieve its value again:

>>>rate=0.075
>>>rate
0.075

The value 0.075 seen in the previous code is an output, because the variable called rate was assigned...