Variables

Introduzione a Python per la finanza

Adina Howe

Associate Professor

Define variables

Store information that can be referenced in code

  • Examples: msft_stock, interest_rate, bonds
  • Name = Value: interest_rate = 0.05

 

Variable names

  • Upper or lower case letters, digits, and underscores
  • Cannot start with a digit
  • Some variable names are reserved in Python (e.g., class or type) and should be avoided
Introduzione a Python per la finanza

Defining variables in Python

# Correct
day_2 = 5   

# Incorrect, variable name starts with a digit
2_day = 5   
Introduzione a Python per la finanza

Using variables to evaluate stock trends

$$ \text{Price to earning ratio} = \frac{\text{Market price}}{\text{Earnings per share}} $$

price = 200
earnings = 5

pe_ratio = price / earnings
print(pe_ratio)
40
Introduzione a Python per la finanza

Let's practice!

Introduzione a Python per la finanza

Preparing Video For Download...