Python staticmethod() function

Published February 17, 2022

In python, the staticmethod() is a built-in function that returns a static method for a specific function.
The syntax of staticmethod() Function

The staticmethod() is written as follows:
 

staticmethod(function to be  converted to a static method)

Example

class Multiplier:
  def multiply_numbers(a, b):
    return a * b
c= Multiplier.multiply_numbers
c = staticmethod(Multiplier.multiply_numbers)
d = c(14, 17)
print('The product of 14 and 17 is:', d)


Output

Python staticmethod function

 

Download Source code

 

Article Contributed By :
https://www.rrtutors.com/site_assets/profile/assets/img/avataaars.svg

256 Views