Kids Coding

A First Class

A class groups data and actions. Make a Player with a name and a score.

KidsAdvancedA First Class

A stamp for many objects

A class is a template. An object is one instance: it has its own data. self means this object.

A Player

class Player:
    def __init__(self, name):
        self.name = name
        self.score = 0

    def add(self, points):
        self.score = self.score + points

sam = Player("Sam")
sam.add(10)
print(sam.name, sam.score)

A class is a cookie cutter; each object you make from it is a cookie. One cutter, many cookies, all the same shape.

Two players, two scores

Separate boxes

class Player:
    def __init__(self, name):
        self.name = name
        self.score = 0

    def add(self, points):
        self.score = self.score + points

a = Player("Sam")
b = Player("Riley")
a.add(5)
b.add(12)
print(a.name, a.score)
print(b.name, b.score)

Real life

Two players on the same football pitch, each with their own score.

Same template (Player). Two objects. Sam’s goals do not add to Riley’s.

Match sheet

class Player:
    def __init__(self, name):
        self.name = name
        self.goals = 0

    def score(self):
        self.goals = self.goals + 1

sam = Player("Sam")
riley = Player("Riley")
sam.score()
sam.score()
riley.score()
print(sam.name, sam.goals)
print(riley.name, riley.goals)

Change one word. Run it. That is how this idea shows up outside the lesson.

Try it

Exercise 1: Make a Book class with title. Create one book and print its title.

Show solution
class Book:
    def __init__(self, title):
        self.title = title

book = Book("Foxes")
print(book.title)

FAQ: A First Class

Common questions about this page.

What is StudyGrid Kids?

StudyGrid Kids is a free coding path for children: Basic, Intermediate, and Advanced. Lessons use Python in the browser. No account and no install.

Should I run a first class examples locally for better learning?

Yes. Use the browser editor on StudyGrid for a quick check, then Download the example and run it on your computer. Local runs show real errors and the real toolchain, which is one of the fastest ways to learn a first class in this Kids Coding Python lesson (A First Class).

Which kids level should we start with?

Start at Basic if the child has never written code. Choose Intermediate if they can print, use variables, and write a simple if. Choose Advanced if they already use loops and lists.

Do kids need an account or an app?

No. Kids pages are public. Code runs in the Try Python editor at /try. We do not ask children for a name or an email.

What language do kids learn?

Python, with a first HTML page in Intermediate and Advanced. After Advanced, the main Python tutorial is the next step.

Is the kids coding track free?

Yes. The Kids home, the three levels, and the Python editor on StudyGrid (studygrid.in) are free.