Last active
February 10, 2019 11:48
-
-
Save Robofied/73c793785c1c3b084436d881f194bae3 to your computer and use it in GitHub Desktop.
Intermediate Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Creating a cutom class with a special method __specialprint__ | |
class custom_class: | |
def __init__(self, name): | |
self.name = name | |
## Creating a special method which is just printing the name associated with the object | |
def __specialprint__(self): | |
print(self.name) | |
## Creating the object | |
c_c = custom_class('Rajesh') | |
## Accessing the special method | |
c_c.__specialprint__() | |
#[Output]: | |
#Rajesh | |
## Checking the special methods associated with our custom class. So, some are default special methods of class and one of our created one | |
print(dir(custom_class)) | |
#[Output]: | |
## 'special_print is a custom special method' | |
#['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__specialprint__', '__str__', '__subclasshook__', '__weakref__'] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment