switching instances

how can i code one prefab to be replaced by another upon button press?

for example: i have a cube Prefab and i press key (F) and it becomes a sphere

simplest way is to have them both in the scene and switch the renderers on and off like so:

public class Example : MonoBehaviour {
public renderer cube;
public renderer sphere;  
  void Update() {
        if (Input.GetKeyDown(KeyCode.F))
            if(cube.enabled)
             {
                  cube.enabled =false;
                 sphere.enabled = true;
              }
           else
               {
                   cube.enabled =true;
                   sphere.enabled = false;
                 }
        
    }
}

thanx it works fine.