Dunder Methods in Hindi

What is Dunder Methods

Python में कुछ ऐसे pre-defined methods होते है जो specific situations में automatically call हो जाते है, इन methods को Dunder Method कहा जाता है। dunder methods के आगे और पीछे double underscore “__” लगा होता है। इन methods को “Magic Method” के नाम से भी जाना जाता है।

Dunder methods का use हम classes and Objects मे करते है और कहीं इसका use आपको जल्दी नहीं मिलेगा। 

Commonly Used Dunder Methods

Dunder Function

Purpose

Small Example

__init__(self, …)

Constructor – object banate समय call होता है

obj = MyClass()

__del__(self)

Destructor – object delete होते समय call

del obj

__str__(self)

Human readable string (print)

print(obj)

__repr__(self)

Official string (debugging/logging)

repr(obj)

__len__(self)

Object की length बताता है

len(obj)

__getitem__(self, key)

Indexing support देता है

obj[0]

__setitem__(self, key, value)

Index पर value assign करता है

obj[1] = 10

__delitem__(self, key)

Index वाली value delete करता है

del obj[2]

__iter__(self)

Iterable बनाता है

for x in obj:

__next__(self)

Next value return करता है

next(obj)

__call__(self, …)

Object को function की तरह call कर सकते हैं

obj()

__contains__(self, item)

Membership test

if 5 in obj:

__eq__(self, other)

Equal (==) operator

obj1 == obj2

__lt__(self, other)

Less than (<) operator

obj1 < obj2

__gt__(self, other)

Greater than (>) operator

obj1 > obj2

__add__(self, other)

Addition (+) operator

obj1 + obj2

__sub__(self, other)

Subtraction (-) operator

obj1 – obj2

__mul__(self, other)

Multiplication (*)

obj1 * obj2

__truediv__(self, other)

Division (/)

obj1 / obj2

__floordiv__(self, other)

Floor Division (//)

obj1 // obj2

__mod__(self, other)

Modulo (%)

obj1 % obj2

__pow__(self, other)

Power (**)

obj1 ** obj2

__enter__(self)

Context manager start

with obj:

__exit__(self, exc_type, exc_val, exc_tb)

Context manager end

with obj:

उम्मीद करते है कि आपको Dunder Methods अच्छे समझ मे आ गया होगा। अपने learning को continue रखने के लिए next button पर click करे,

Add a comment...

  • All Posts
  • Artificial Intelligence
  • Computer Fundamentals
  • Computer Networks
  • Data Analytics
  • Data Science
  • DBMS
  • Deep Learning
  • Digital Electronics
  • DSA with Python
  • Excel
  • Exercise
  • Git & Github
  • Machine Learning
  • Matplotlib
  • Natural Language Processing
  • NumPy
  • Operating System
  • Pandas-s
  • Power BI
  • Python Tutorial
  • Scikit-learn
  • Seaborn
  • SQL & MySQL
computer networks

Table of Contents All Chapters 1. OSI Model      1.1. Physical Layer      1.2. Data Link Layer  ...

computer networks

Table of Contents All Chapters 1. Topology 2. Types of Topology      2.1. Point to Point Topology    ...

computer networks

Table of Contents All Chapters 1. Data Communication 2. Types of Data Communication      2.1. Simplex      2.2....

digital electronics number system

Table of Contents All Chapters 1. Logic Gate 2. AND Gate      2.1. AND Gate Truth Table 3. OR...

Edit Template

Sign up to track your learning

Login to continue your learning tracking

To reset your password, please enter your email address or username below.

Scroll to Top