Skip to content

Instantly share code, notes, and snippets.

@gwsu2008
Last active January 3, 2020 05:37
Show Gist options
  • Save gwsu2008/38e6af1f31d3c0390e761d52e66f6cbd to your computer and use it in GitHub Desktop.
Save gwsu2008/38e6af1f31d3c0390e761d52e66f6cbd to your computer and use it in GitHub Desktop.
Python sample staticmethod in class
# app.py
# Defining a class named Sum
class Sum:
# defining a function sumoftwo
# this function will be called in a static method
# Creating static method here only
@staticmethod
def sumoftwo(a, b):
return a+b
class Sum2:
# defining a function sumoftwo
# this function will be called in a static method
def sumoftwo(a, b):
return a+b
# Creating Static Method
Sum2.sumoftwo = staticmethod(Sum.sumoftwo)
# Printing values by passing arguments
print("Sum of two numbers are: ", Sum2.sumoftwo(10, 20))
# Printing values by passing agruments
print("Sum of two numbers are: ", Sum.sumoftwo(10, 20))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment