Can i use the same key to enable and disable the gameobject ?

Hello everyone
I’m new in using Unity. I have a question when i do a game.
Can i use the same key to enable and disable the gameobject ?

For example
Press Z will change the weapon , the last weapon will disable .
How can i do it ?

im pretty new too, but maybe u can use something like

public int whatWeapon;

void Update()
{
      if(Input.GetKeyDown("Z"))
         {
                if(whatWeapon == 1)
                     {
                       use axe
                      }
         if(whatWeapon == 2)
                     {
                      use sword
                      }

}

}

hope that can help you