Multimethods in Python Last Updated : 21 Apr, 2020 Comments Improve Suggest changes Like Article Like Report Multimethod basically means a function that has multiple versions, distinguished by the type of the arguments. For better understanding consider the below example. @multimethod def sum(x: int, y: int): return x + y @multimethod def sum(x: str, y: str): return x+" "+y The above example is similar to def sum(x, y): if isinstance(x, int) and isinstance(y, int): return x + y elif isinstance(x, str) and isinstance(y, str): return x + ' ' + y Installation At syntactical level, Python does not support multiple dispatch but it is possible to add multiple dispatch using a library extension multimethod. To install this library type the below command in the terminal. pip install multimethod Example 1: Python3 # Python program to demonstrate # multimethods from multimethod import multimethod # Function that will be called # for integer addition @multimethod def sum(x: int, y: int): return x + y # Function that will be called # for string addition @multimethod def sum(x: str, y: str): return x+" "+y # Driver's code print(sum(2, 3)) print(sum("Hello", "World")) Output: 5 Hello World Example 2: Python3 # Python program to demonstrate # multimethods from multimethod import multimethod class GFG(object): @multimethod def double(self, x: int): print(2 * x) @multimethod def double(self, x: complex): print("sorry, I don't like complex numbers") # Driver Code obj = GFG() obj.double(3) obj.double(6j) Output: 6 sorry, I don't like complex numbers Comment More infoAdvertise with us Next Article Multimethods in Python N nikitadabral30 Follow Improve Article Tags : Python python-modules Python Decorators Practice Tags : python Similar Reads Multithreading in Python This article covers the basics of multithreading in Python programming language. Just like multiprocessing , multithreading is a way of achieving multitasking. In multithreading, the concept of threads is used. Let us first understand the concept of thread in computer architecture. What is a Process 8 min read Python List methods Python list methods are built-in functions that allow us to perform various operations on lists, such as adding, removing, or modifying elements. In this article, weâll explore all Python list methods with a simple example.List MethodsLet's look at different list methods in Python:append(): Adds an 3 min read Python __add__() magic method Python __add__() function is one of the magic methods in Python that returns a new object(third) i.e. the addition of the other two objects. It implements the addition operator "+" in Python. Python __add__() Syntax Syntax: obj1.__add__(self, obj2) obj1: First object to add in the second object.obj2 1 min read Python | os.cpu_count() method ]os.cpu_count() method in Python is used to get the number of CPUs in the system. This method returns None if the number of CPUs in the system is undetermined. In this article, we will see how to get several cores in Python. Python os.cpu_count() Method SyntaxSyntax: os.cpu_count() Parameter: No par 1 min read Dunder or magic methods in Python Python Magic methods are the methods starting and ending with double underscores '__'. They are defined by built-in classes in Python and commonly used for operator overloading. They are also called Dunder methods, Dunder here means "Double Under (Underscores)". Python Magic MethodsBuilt in classes 7 min read Like