Last active
January 3, 2020 05:37
-
-
Save gwsu2008/38e6af1f31d3c0390e761d52e66f6cbd to your computer and use it in GitHub Desktop.
Python sample staticmethod in class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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