Sponsored Reserved space — layout preview until AdSense is connected

Python Data Types

Hands-on tour of int, float, str, bool, list, tuple, dict, and None — with runnable snippets.

Focus: python data types basics

Practice in the browser IDE

Runnable sample for this lesson loads into the editor — press Run when you’re ready.

Try in editor

Sponsored

Sponsored Reserved space — layout preview until AdSense is connected

Every value in Python has a type. Python picks types from literals like 42 or "hi". Each gray box below is one runnable sample — use the small Try in editor chip to open the IDE with that exact code loaded (?example=…).

1. Numbers — integers and floats

An integer (int) is a whole number. A float (float) has a decimal point. Underscores in literals are only for readability.

Runnable sampleTry in editor
count = 7
million = 1_000_000
avg = 9.5

print(count + 2)       # 9
print(type(count))     # <class 'int'>
print(type(avg))       # <class 'float'>

2. Text — strings (str)

Strings hold text. Match your quotes; use \n inside quotes for a newline.

Runnable sampleTry in editor
name = "Ada"
emoji = '🐍'
story = "Line one.\nLine two."

print(len(name))
print(name.lower())
print("Hello, " + name)
print(story)

3. Yes / no — booleans (bool)

Only two values: True and False (capital letter first). Comparisons return booleans.

Runnable sampleTry in editor
logged_in = True
print(10 > 3)
print("python" == "java")

4. Lists — ordered, changeable

A list keeps items in order. You can append, remove, or replace items.

Runnable sampleTry in editor
scores = [88, 92, 79]
scores.append(95)
first = scores[0]

print(scores)
print(len(scores))

5. Tuples — ordered pairs / records

A tuple is like a fixed-length list you usually do not mutate — handy for coordinates.

Runnable sampleTry in editor
point = (10, 20)
rgb = (255, 128, 0)

print(point[0], rgb[2])

6. Dictionaries — label → value

A dict maps keys (often strings) to values. Lookup by key is fast and readable.

Runnable sampleTry in editor
user = {"name": "Sam", "score": 42}
print(user["name"])
user["score"] = 100

print(list(user.keys()))
print(list(user.values()))

7. None — nothing assigned yet

None means “no useful object here.” Prefer is None when comparing.

Runnable sampleTry in editor
answer = None
print(answer is None)

8. Check any value’s type

Use type() while learning what Python stored.

Runnable sampleTry in editor
samples = [42, 3.14, "hi", True, [1], (2,), {"k": 3}, None]
for item in samples:
    print(repr(item), "->", type(item).__name__)

How this relates to databases (simple picture)

In SQLite (and SQL generally), each column stores one kind of value — numeric, text, blob, etc. In Python you pick types that fit your problem; drivers map Python values into SQL safely.

Practice

Use each snippet chip above, or the compact Try in editor button under the lesson title for the combined playground preset.

Sponsored

Sponsored Reserved space — layout preview until AdSense is connected

Sponsored

Sponsored Reserved space — layout preview until AdSense is connected

Discussion

Questions, corrections, and tips help everyone reading this page.

1 comment

Add a comment

Shown publicly with your comment.

Be constructive · max 4,000 characters
Fapebac202

Member

Does this really help?
Reply