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

Python · Theory

Classes and Objects in Python

← All stacks

Theory

55/268

Classes and Objects in Python

A class is the blueprint. An object is one real thing made from it. class Student: is the idea of a student. s = Student("Asha", 12) is one student sitting in the room. Two objects can have different names and rolls.

__init__ runs when you create the object. self is that object. self.name = name stores the field on it. Forget self and you get TypeError or a variable that vanishes. Every method’s first parameter is self — you don’t pass it at the call site.

Let’s take this on the board. class Student with __init__(self, name, roll). s = Student("Asha", 12). print(s.roll, s.name) → 12 Asha. Class is Student. Object is s. That is the whole idea for a fresher viva.

Classes and Objects in Python — output — 12 Asha. Student is the class; s is one real object.

Diagram
class Student   (blueprint)
         │ Student("Asha", 12)
         ▼
   s1 Asha roll 12
Exam tip

Explain self and __init__ together.

Example

# Classes and objects
class Student:
    def __init__(self, name, roll):
        self.name = name
        self.roll = roll

s = Student("Asha", 12)
print(s.roll, s.name)

Classes and Objects in Python — output: 12 Asha. Student is the class; s is one real object.

Short notes

  • DefClass = blueprint
  • RuleObject = instance
  • RememberSelf current object
  • Use__init__ setup

Questions

1

Explain Classes and Objects 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 Classes and Objects?

Previous← OOPs Concepts in PythonNextConstructors 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.