Python: getting started

Lesson 04 · 11 min

Classes, self, methods

A class describes a shape. self is this instance. Don't confuse a class with an object.

11 minLesson 4 of 8Practice includedAsk AI on any point

class User: and a method def greet(self):. The first argument of a method is the object itself; by convention it's called self. You create one like this: u = User(). Fields are set in __init__: self.name = name. Forget self and the name won't stick to the instance.

Sign in to continue

The rest of this lesson opens after sign up

The first lesson of every course is open without an account. To read on, solve the practice and use Ask, create a free account or log in.