Is it possible to format the input from the serial monitor?

What you describe in your original post would look a little different using Micropython, the Micropython code

"import machine\nimport utime\n\ngpio0 = machine.Pin(0, machine.Pin.OUT)\ngpio45 = machine.Pin(45, machine.Pin.OUT)\nutime.sleep(1)\ngpio45.value(0)\ngpio0.value(1)";

is something that you can enter via the REPL, you should know about the REPL if you have not come across the REPL yet do a search to get familiar.

It is possible to create a desktop app with your own REPL or there is a debugging tool called aiorepl which allows you to modify and query a running application.

So the answer to your original question is yes you can but it would help to know what you want to achieve and if you have a particular reason why you would want to do that.