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 :: lambda 
Python :: django reverse vs reverse_lazy 
Python :: Python RegEx re.compile() 
Python :: smtp python 
Python :: python escape forward slash 
Python :: picture plot 
Python :: upload file setup django url 
Python :: add element to list 
Python :: sum of even numbers 
Python :: elif python 
Python :: what is django python 
Python :: how to split python string into N numbers equally 
Python :: python increment by 1 
Python :: list all files in a folder 
Python :: add header info in django response 
Python :: replace by positions a string in a list with another string python 
Python :: python built in libraries 
Python :: python look for image on screen 
Python :: pandas save dataframe with list 
Python :: Program to Compute LCM Using GCD 
Python :: google youtuve api python 
Python :: numpy column 
Python :: variable python 
Python :: merge sorting in python 
Python :: sessions in flask 
Python :: python image heatmap 
Python :: python incrémentation 
Python :: for _ in range() in python 
Python :: python use cases 
Python :: python all 
ADD CONTENT
Topic
Content
Source link
Name
9+7 =