HelpContactFor teachers and institutes
>_StemPy Lab
Mock TestsClasses

>_StemPy Lab

Learn. Solve. Code the solutions. Test yourself.

Live examsFree mock exams, timed and rankedEveryone starts together, and your score and rank come the moment it ends.See the exams →

Learn

  • Physics
  • Chemistry
  • Mathematics
  • Biology
  • Python Programming
  • Statistics & Data Science
  • Classes
  • Groups

Practice

  • Problems
  • Quizzes
  • Mock Tests
  • Prepare for an Exam
  • Question Sets
  • Exams
  • Certificates
  • Python Labs
  • AI Practice Generator
  • Student-Created Tests

Community

  • Discussions
  • Resources
  • Notes
  • Glossary
  • Blog

Account

  • Log in
© 2026 senLearn. All rights reserved.HelpAboutContactPrivacy PolicyTerms of UseRefund Policy
  1. Glossary
  2. /Python and data
  3. /Class and Special Methods (in Python)

What is Class and Special Methods (in Python)?

In short

A class is a blueprint for making objects that hold data and the functions that work on it. Special methods, with names like __init__ and __str__, let an object behave like a built-in type.

In simple words

__init__ runs when an object is made and sets up its data. __str__ decides what print shows. Others such as __add__ let you use + with your own objects. The first parameter of every method is self, the object itself. Classes are useful in science to model a particle, a planet or a vector with its own properties.

Example

This prints Ball of 0.5 kg.

Also searched as: python special methods.

Learn it properly

  • Lessons on this topic
  • Test yourself

Related terms

  • Function (in Python)
  • Variable (in Python)

← All glossary terms

Learn it in

  1. Classes and ObjectsClass 11 to 12
All lessons on this topic →

Practise

  1. A class Dog has the attributes name and age…Medium
  2. A class Basket has def __init__(self, items=[]) and self.items = items…Medium
  3. Class or object attribute?Medium
  4. Using the BankAccount class of the lesson, add a method transfer(other, amount) that…Medium

Quick questions

  1. A student writes a small stack class. The program does not do what the student expects.…Hard
  2. A book object gets its own shelf, which hides the class variable. Which of these…Advanced
  3. Two players share a class variable, and one of them gets its own value with setattr.…Hard

More Python and data terms

  1. Cell (in a Python notebook)
  2. Dictionary (in Python)
  3. For Loop
  4. If Statement (in Python)
  5. Import (Python modules and libraries)
  6. List (in Python)
All Python and data terms →

Try it yourself

Python labs run in your browser. Type the code, run it and see what happens.

Open a Python lab