>>>Task
Not everything fits into an int, a str or a list. A class is a custom type you
define yourself, bundling related values — and later, functions — into one thing.
You start one with the class keyword, a name, and a colon:
class Person:
def __init__(self, name, age):
self.name = name
self.age = age__init__ — short for initialize, with two underscores each side — runs every time you
make one. Its job is to set up the attributes: the values this particular instance will
carry around.
self is the instance being worked on. Every method takes it as its first parameter, and
self.name = name means "store this argument on this object". It is a quirk of Python
that you write it out; you get used to it.
To create one, call the class by name — the arguments go to __init__, and you never pass
self yourself:
p = Person("Ada", 36)
p.name # "Ada"Define a class Person whose __init__ takes name and age and stores both.
Then create two of them:
p1 — Toby, aged 16p2 — Dumbledore, aged 115The solution unlocks after a few minutes.
Run your code to see the output.