class Calculator:
# create addNumbers static method
@staticmethod
def addNumbers(x, y):
return x + y
print('Product:', Calculator.addNumbers(15, 110))
import random
class Example:
# A static method doesn't take the self argument and
# cannot access class members.
@staticmethod
def choose(l: list) -> int:
return random.choice(l)
def __init__(self, l: list):
self.number = self.choose(l)
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'checkstatic/static/')
]
def squares(length):
for n in range(length):
yield n ** 2
Code language: Python (python)
class A(object):
@staticmethod
def stat_meth():
print("Look no self was passed")
>>> a = A()
>>> a.stat_meth()
Look no self was passed