Double underscore before and after a name

The name starts with __ and ends with the same considering special methods in Python. Python provides these methods to use as the operator overloading depending on the user. Python provides this convention to differentiate between the user-defined function with the module’s function 

Python3




class Myclass():
    def __add__(self,a,b):
        print (a*b)


Calling from Interpreter

 



Underscore (_) in Python

In this article, we are going to see Underscore (_) in Python.

Following are different places where “_” is used in Python:

  • Single Underscore:
    • Single Underscore in Interpreter
    • Single Underscore after a name
    • Single Underscore before a name
    • Single underscore in numeric literals
  • Double Underscore:
    • Double underscore before a name
    • Double underscore before and after a name

Similar Reads

Single Underscore

Example 1: Single Underscore In Interpreter:...

Double underscore before a name

...

Double underscore before and after a name

...

Contact Us