xxxxxxxxxx
def squares(length):
for n in range(length):
yield n ** 2
Code language: Python (python)
xxxxxxxxxx
class Calculator:
# create addNumbers static method
@staticmethod
def addNumbers(x, y):
return x + y
print('Product:', Calculator.addNumbers(15, 110))
xxxxxxxxxx
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'checkstatic/static/')
]
xxxxxxxxxx
Static method
class Circle:
pi = 3.14 """Static methods can't access object attributes or methods, but they can use class variables."""
@staticmethod """Static methods don't need to have an instance of the class to call them."""
def area(radius):
return Circle.pi*radius*radius
print(Circle.area(5))