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

Initializing the variable


From the previous example, we know that after we assign a value to x, we can use x, which means that x is now defined in the sense of other computer languages such as FORTRAN and C/C++. The opposite is also true, that we could not use X if it is not assigned a value in Python. In other words, when we assign a value to X, we have to define it first. Compared to languages such as C++ or FORTRAN, we don't have to define x as an integer before we assign 10 to it.

Another advantage is that we could change the data type of a variable easily. For the FOTRAN language, if we have defined x as an integer, we cannot assign a string to it. Since there is only assignment in Python, we could assign any value to a variable. For example, we could assign 10 to x. It is legal to assign a string, such as Hello World, to x in the next minute. However, we should not be confused with the data type conversion, such as converting an integer to a string or vice versa. Conversion between different data types will be discussed in the later chapters.