Variables and Data Types
Python variables, int, float, str, bool — the building blocks of every script
Variables store values that your script works with. Unlike Excel cells (A1, B2), Python variables have names you choose — making your code readable and reusable. Python is dynamically typed: you do not declare the type — Python figures it out from the value you assign.
The four basic data types you use constantly in data analysis: int (whole numbers), float (decimal numbers), str (text), and bool (True/False). Understanding them prevents type errors — one of the most common Python mistakes for beginners.
Examples
Key Points
- ✓Python variables need no declaration — just assign: x = 10
- ✓int / int gives float in Python 3: 7 / 2 = 3.5 (not 3)
- ✓f-strings (f"value is {variable}") are the best way to format output
- ✓Use snake_case for variable names: total_sales not totalSales
- ✓None is Python's equivalent of NULL — check with: value is None
Practice Question
What is the result of: 7 // 2 in Python?
Related Topics
String Operations in PythonSlice, split, replace, strip and format text data — essential for cleaning messy datasetsPython ListsStore, access and manipulate collections of data with Python listsDictionaries in PythonKey-value pairs for fast lookups, mappings and structured dataConditionals — if, elif, elseWrite if/elif/else logic to categorise, flag and filter data in Python