Same button for pick up and drop

Godot Version

4.3

Question

how can I make a button so that when the player presses it for the first time, he picks up an object, and on the second press, if the object is in his hands, the player throws the object?

Your description seems to be pseudo code already?

   if not object_in_hands:
    pickup(object) # sets object_in_hands to object
  else:
    drop(object_in_hands)

set_meta to button &‘holds’=true
then check
if Button.get_meta(&‘holds’, false)==true: then drop