Static Method in Python
Level 4166 keystrokes
This defines static methods that don't need an instance, printing 7 and 12. Static methods belong to the class, not instances.
Python code
# Define a class to group related utility functions1class MathUtils: # @staticmethod decorator creates a method without self parameter2 @staticmethod3 def add(a, b): # Simply returns the sum of two numbers4 return a + b5 6 @staticmethod7 def multiply(a, b): # Returns the product of two numbers8 return a * b9 # Call static methods directly on the class (no instance needed)10print(MathUtils.add(3, 4))11print(MathUtils.multiply(3, 4))Output
7 12
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this Python code and how often they appear.
(× 6)× 6,× 4:× 3.× 2@× 2*× 1+× 1