Answers for "double underscore methods python"

0

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
Posted by: Guest on February-15-2022
0

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
Posted by: Guest on August-12-2021

Code answers related to "double underscore methods python"

Python Answers by Framework

Browse Popular Code Answers by Language