Kerbal space program number binding
Solution 1:
You can do this with Action Groups.
This youtube tutorial provides a good example of how to do exactly what you want:
In short, once you have the solar panels added to your ship:
Click on the "Action Groups" icon at the top of the screen. It's the blue button that looks like two gears.
Select "Custom1" or whichever number you would like the action to bind to.
Click on the solar panels you would like to extend/retract when the key is pressed.
Then select "Toggle Panels" (or "Extend Panels"/"Retract Panels", if you only want this action to work in one direction.)
Now when your ship is launched, you can use whichever number key you bound this action group to to toggle your solar panels.