Python staticmethod()
staticmethod() are a special case of methods. Any functionality that belongs to a class, but doesn’t require the object is placed in the static method. Static methods are similar to class methods. The main difference is that a static method doesn’t receive any additional arguments.
Remember that, a static method doesn’t use the self variable and it is defined using a built-in function named staticmethod. Python has a handy syntax, called a decoder is used to make it easier to apply the staticmethod function to the method function definition. It has the following syntax:
@staticmethod def name(args...): statements
Example:
class choice: def __init__(self, subjects): self.subjects=subjects @staticmethod def validate_subject(subjects): if "C#" in subjects: print("This book is not available now!") else: return True subjects=["C", "C++", "C#", "Java", "Python"] if all(choice.validate_subject(i) for i in subjects ): ch=choice(subjects) print("You have already kept this book!")