Variabelen

Introductie tot Python voor Finance

Adina Howe

Associate Professor

Variabelen definiëren

Sla info op die je in code kunt gebruiken

  • Voorbeelden: msft_stock, interest_rate, bonds
  • Naam = Waarde: interest_rate = 0.05

 

Variabelnamen

  • Hoofd-/kleine letters, cijfers en underscores
  • Mag niet met een cijfer beginnen
  • Sommige namen zijn gereserveerd in Python (bv. class of type) en moet je vermijden
Introductie tot Python voor Finance

Variabelen definiëren in Python

# Correct
day_2 = 5   

# Incorrect, variable name starts with a digit
2_day = 5   
Introductie tot Python voor Finance

Variabelen gebruiken voor aandelentrends

$$ \text{Koers-winstverhouding} = \frac{\text{Marktprijs}}{\text{Winst per aandeel}} $$

price = 200
earnings = 5

pe_ratio = price / earnings
print(pe_ratio)
40
Introductie tot Python voor Finance

Laten we oefenen!

Introductie tot Python voor Finance

Preparing Video For Download...