Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

double underscore methods python

# officially called as dunder methods
# mostly class in python is a subclass of objects which has dunder methods.

class Test:
  def __str__(self):
    return "This is just for test"
  def __add__(self, x):
    return 6 + x
  
sample = Test()
print(sample) # calls __str__, also gets called when str(sample)
print(sample + 9)  # calls __add__
  
# Refer this for many such methods: https://diveintopython3.net/special-method-names.html
Comment

python double underscore methods

Double underscore methods are special methods defined by Python 
that can serve a special purpose. 

Ex: 
  __eq__ : determines what to do when determining 
    	   equality (==) of a certain object
Comment

PREVIOUS NEXT
Code Example
Python :: logistic regression sklearn 
Python :: python def example 
Python :: Python NumPy Reshape function example 
Python :: unittest 
Python :: django form date picker 
Python :: numpy.dot 
Python :: python dictionaries 
Python :: simulation? 
Python :: del(list) python 
Python :: print column name and index dataframe python 
Python :: how to use inputs in python 
Python :: pivot tables pandas explicación 
Python :: Python - How To Convert String to ASCII Value 
Python :: asyncioevents.py", line 504, in add_reader raise NotImplementedError 
Python :: python pprint on file 
Python :: python string: indexing and slicing string 
Python :: codegrepper is cool 
Python :: wails get started 
Python :: Second step creating python project 
Python :: receive ouput subprocess call 
Python :: python check if division has remainder 
Python :: #clearing all keys new key in python 
Python :: pandas mask string contains 
Python :: video in python without cv2 
Python :: flask run function every minute 
Python :: table is not creating in django 
Python :: Method to get column average 
Python :: flask get summernote text 
Python :: convert month weeks days into month days in python pandas 
Python :: who is bayceee roblox id 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =