PGoCareerGoCareer prep tools
Home
LoginSign up
  • Java
  • Python
  • AI
  • React
  • Angular
  • PHP
  • Node.js
  • SQL
  • DSA
  • HTML
  • CSS
  • JS
  • Spring
  • ML
  • MongoDB

Python · Theory

Constructors in Python

← All stacks

Theory

56/268

Constructors in Python

__init__ is the initializer most people mean by constructor. It runs when you create the object: s = Student("Asha", 12). Inside, self.name = name stores fields. You do not call __init__ yourself. Student(...) does it. Forget self on the first parameter and you get TypeError.

__new__ actually creates the instance — advanced, skip unless they ask. Viva signature: def __init__(self, name, roll). Then one object on the board: print(s.name) → Asha.

Constructors in Python — output — 4. Box(4) calls __init__ and sets side.

Exam tip

__init__(self, ...) + one Student example.

Example

# Constructor
class Box:
    def __init__(self, side):
        self.side = side

b = Box(4)
print(b.side)

Constructors in Python — output: 4. Box(4) calls __init__ and sets side.

Short notes

  • Def__init__ runs on create.
  • Ruleself first. Store attributes.
  • RememberDon’t call __init__ by hand.

Questions

1

Explain Constructors as if you are teaching a junior — definition, then one tiny script.

2

What does the example print, and why?

3

What mistake do freshers make with Constructors?

Previous← Classes and Objects in PythonNextInheritance in Python →
P

GoCareerGo

Utilities · Preparation Hub · Resume · CV · Tools — one workspace.

Workspace

DashboardProfilePreparation HubResume builderCV builderCareer planning

PDF Tools

Merge PDFSplit PDFCompress PDFImage to PDFAll toolsJobs

Image & QR

Compress ImageResize ImageQR ScannerQR GeneratorBlogIT interview prep

Company

FAQFeedbackContactPrivacyTermsSitemap

© 2026 GoCareerGo. Keep moving forward.