Python में Object-Oriented Programming परिचय
George Boorman
Curriculum Manager, DataCamp
| पद | परिभाषा |
|---|---|
| Class | ऑब्जेक्ट बनाने के लिए एक ब्लूप्रिंट/टेम्पलेट |
| Object | डेटा और फंक्शनैलिटी का संयोजन; किसी क्लास का इंस्टेंस |
| पद | परिभाषा |
|---|---|
| Class | ऑब्जेक्ट बनाने के लिए एक ब्लूप्रिंट/टेम्पलेट |
| Object | डेटा और फंक्शनैलिटी का संयोजन; किसी क्लास का इंस्टेंस |
| State | किसी ऑब्जेक्ट से जुड़ा डेटा, जो attributes से असाइन होता है |
| Behavior | ऑब्जेक्ट की फंक्शनैलिटी, जो methods से परिभाषित होती है |
| ऑपरेटर | मेथड |
|---|---|
== |
__eq__() |
!= |
__ne__() |
>= |
__ge__() |
<= |
__le__() |
> |
__gt__() |
< |
__lt__() |
__str__()print(obj), str(obj)print([1,2,3])
[1 2 3]
str([1,2,3])
'[1, 2, 3]'
__repr__()repr(obj), कंसोल में प्रिंटिंगrepr([1,2,3])
[1,2,3]
[1,2,3]
[1,2,3]
print() के लिए fallbackclass BalanceError(Exception): passclass 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 परिचय