if len(each_file) > 0: for file in each_file: ..... if not starting_stock_value: starting_stock_value = stock_price if not starting_sp500_value: starting_sp500_value = sp500_value .....
Question:
1. I'm having some trouble understanding the portion of the (abbreviated) code above. As I understand it, you set starting_stock_value and starting_sp500_value to 'False' before you enter the loops where data is processed. I get conceptually that we want the earliest price for each security to be our 'base' and that there is no change (since there is no prior price). What I don't understand is how 'if not ...' is working. We initially set starting_stock_value and starting_sp500_value to 'False'. When we get down to 'if not...' on the first run the value is 'True' ('if not "False") so we set starting_stock_value to the initial stock price. When we loop through each file for a particular stock, does the 'if not' statement no longer execute because starting_stock_value and starting_sp500_value are not boolean (floats) and aren't reset to a boolean until the next security (when they are set back to false)?
Thanks in advance.
You must be logged in to post. Please login or register an account.
So we start with False, just to start with False and so we can use that logic. IF there is a value at all, it can be anything...besides 0 or False of course... then it will be True.
-Harrison 8 years ago
You must be logged in to post. Please login or register an account.
Thank you.
-mksamelson 8 years ago
You must be logged in to post. Please login or register an account.