Page2/20
Variables & Data Types Β· Page 2 of 5
Python's 4 Core Data Types
The 4 Core Scalar Data Types
Python has four basic types for storing single values:
1. String (str) β Text Data
Store any text: names, sentences, files paths, anything!
name = "Alice"
city = 'New York' # Single or double quotes, same thing
message = "Score: 95%" # Can include numbers/symbols
2. Integer (int) β Whole Numbers
For counting and discrete values (no decimals).
age = 28
count = 100
negative = -5
big_number = 1_000_000 # Python allows underscores for readability
3. Float (float) β Decimal Numbers
For measurements, percentages, and precise values.
price = 19.99
pi = 3.14159
percentage = 85.5
4. Boolean (bool) β True or False
For decisions and logical checks (exactly 2 values).
is_student = True
is_graduate = False
passed_exam = True
Quick Reference Table
| Type | Example | Use Case |
|---|---|---|
str | "Alice" | Names, text, labels |
int | 28 | Ages, counts, IDs |
float | 3.14 | Measurements, scores |
bool | True | Yes/No, On/Off, conditions |
Checking Variable Type
Use the type() function to ask: "What type is this variable?"
type(42) # <class 'int'>
type("Alice") # <class 'str'>
type(3.14) # <class 'float'>
type(True) # <class 'bool'>
This becomes super useful when debugging! π
main.py
Loading...
OUTPUT
βΆClick "Run Code" to executeβ¦