Variables and Data Types
In programming, a variable is a container that holds a value. Think of it as a labeled box where you store information you'll use later.
Creating Variables
Let's create some variables for financial data:
Loading Python Playground...
The = sign doesn't mean "equals" in the mathematical sense - it means "assign the value on the right to the variable on the left."
Variable Naming Rules
Variable names in Python:
- Can contain letters, numbers, and underscores
- Must start with a letter or underscore (not a number)
- Are case-sensitive (
stockPriceandstockpriceare different) - Cannot use reserved words like
if,for,while
Good vs Bad Variable Names
Loading Python Playground...
Data Types in Python
Python automatically determines what type of data you're storing. Understanding these types is crucial for financial work.
Integers (int) - Whole numbers
Loading Python Playground...
Floating-Point Numbers (float) - Decimals
Loading Python Playground...
Strings (str) - Text
Loading Python Playground...
Booleans (bool) - True/False
Loading Python Playground...
Practice Exercise
Loading Python Exercise...
Key Takeaways
- Variables store data that you can use later
- Use descriptive names to make code readable
- Integers are whole numbers (shares, years)
- Floats are decimals (prices, returns)
- Strings are text (ticker symbols, company names)
- Booleans are True/False values (yes/no conditions)
Next, we'll learn how to perform calculations with these variables using arithmetic operations!

