Войти
  • 17021Просмотров
  • 1 год назадОпубликованоBro Code

Learn Python STATIC METHODS in 5 minutes! ⚡

# Static methods = A method that belong to a class rather than any object from that class (instance) # Usually used for general utility functions # Instance methods - Best for operations on instances of the class (objects) # Static methods - Best for utility functions that do not need access to class data class Employee: def __init__(self, name, position): = name = position #INSTANCE METHOD def get_info(self): return f"{ } = { }" @staticmethod def is_valid_position(position): valid_positions = ["Manager", "Cashier", "Cook", "Janitor"] return position in valid_positions print( ("Rocket Scientist"))