2/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

TypeExampleUse Case
str"Alice"Names, text, labels
int28Ages, counts, IDs
float3.14Measurements, scores
boolTrueYes/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…