Raspberry Pi - gpiozero Library
You want to create a Button class that supports both on_press and on_release callbacks. Which code correctly implements this so pressing and releasing the button calls the right functions?
class Button:
def __init__(self):
# What should go here?
def press(self):
# What should go here?
def release(self):
# What should go here?
button = Button()
button.on_press = lambda: print('Pressed')
button.on_release = lambda: print('Released')
button.press()
button.release()