Skip to the workspace
Pebellslearn by building

Python syntax & reference

Find the form you need, compare how it behaves, and open the complete explanation when you need more depth.

Python 3.10+ syntax; individual entries identify newer features. Browser exercises use the configured Python runner.

1 matching syntax entry

Classes and instance state

Learn in depth →

A class defines behavior; instances hold their own state through attributes.

class Name:
    def __init__(self, value): ...

Example

class Counter:
    def __init__(self):
        self.value = 0
    def increment(self):
        self.value += 1
c = Counter()
c.increment()
print(c.value)

Result

1

Watch for: A mutable class attribute is shared across instances unless shadowed. Initialize per-instance lists in __init__.

Practise this topic →
Complete explanation index (91 lessons indexed)

Classes & Instances

Technical sources and review date

Original Pebells examples. Reviewed 2026-10-28.

Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.