बधाई

Python में Object-Oriented Programming परिचय

George Boorman

Curriculum Manager, DataCamp

Classes और objects

पद परिभाषा
Class ऑब्जेक्ट बनाने के लिए एक ब्लूप्रिंट/टेम्पलेट
Object डेटा और फंक्शनैलिटी का संयोजन; किसी क्लास का इंस्टेंस
Python में Object-Oriented Programming परिचय

Attributes और methods

पद परिभाषा
Class ऑब्जेक्ट बनाने के लिए एक ब्लूप्रिंट/टेम्पलेट
Object डेटा और फंक्शनैलिटी का संयोजन; किसी क्लास का इंस्टेंस
State किसी ऑब्जेक्ट से जुड़ा डेटा, जो attributes से असाइन होता है
Behavior ऑब्जेक्ट की फंक्शनैलिटी, जो methods से परिभाषित होती है
Python में Object-Oriented Programming परिचय

मुख्य कॉन्सेप्ट

Encapsulation:

  • डेटा और मेथड्स का बंडलिंग

Inheritance:

  • मौजूदा कोड की फंक्शनैलिटी बढ़ाना

Polymorphism:

  • एकीकृत इंटरफ़ेस बनाना
Python में Object-Oriented Programming परिचय

तुलनाएँ

ऑपरेटर मेथड
== __eq__()
!= __ne__()
>= __ge__()
<= __le__()
> __gt__()
< __lt__()
Python में Object-Oriented Programming परिचय

String representation

__str__()

  • print(obj), str(obj)
print([1,2,3])
[1 2 3]
str([1,2,3])
'[1, 2, 3]'
  • अनौपचारिक, end user के लिए
  • string representation

__repr__()

  • repr(obj), कंसोल में प्रिंटिंग
repr([1,2,3])
[1,2,3]
[1,2,3]
[1,2,3]
  • औपचारिक, डेवलपर के लिए
  • reproducible representation
  • print() के लिए fallback
Python में Object-Oriented Programming परिचय

Error-handling

class BalanceError(Exception): 
    pass

class Customer: def __init__(self, name, balance): if balance < 0 : raise BalanceError("Balance has to be non-negative!") else: self.name, self.balance = name, balance
# Use try-except to catch errors try: cust = Customer("Larry Torres", -100) except BalanceError: cust = Customer("Larry Torres", 0)
Python में Object-Oriented Programming परिचय

अगला क्या?

  • Multiple inheritance
  • Descriptors
  • Custom attributes
  • Custom iterators
  • Type hints
  • Abstract base classes
Python में Object-Oriented Programming परिचय

अभ्यास करते हैं!

Python में Object-Oriented Programming परिचय

Preparing Video For Download...