Introduction

Objects group data with related behavior. A class describes how to create those objects. Model a small concept first, such as a learner with a name and a greeting, and keep responsibilities clear.

Syntax & example

class Learner:
    def __init__(self, name):
        self.name = name
    def greet(self):
        return "Hello, " + self.name

print(Learner("Alex").greet())

Expected output

Hello, Alex

Common mistakes

  • Using a variable before assigning a value to it.
  • Mixing text and numbers without converting deliberately.
  • Skipping an empty input or a boundary value when testing.

Practice

Create a second learner with a different name.

13px
main.pyYour ideas, in code.
Loading your editor…
Run your code to see the output here.
Ready to buildUTF-87 lines